new Tracer().warn("Unbalanced quotes in [%s] for %s (value=%s)%n", temp, argSpec, value); quotedValues.add(temp.toString()); temp.setLength(0); new Tracer().warn("Unable to respect quotes while splitting value %s for %s (unprocessed remainder: %s)%n", value, argSpec, quotedValues); return value.split(splitRegex, limit);
/** Ensures all attributes of this {@code CommandSpec} have a valid value; throws an {@link InitializationException} if this cannot be achieved. */ void validate() { Collections.sort(positionalParameters, new PositionalParametersSorter()); validatePositionalParameters(positionalParameters); List<String> wrongUsageHelpAttr = new ArrayList<String>(); List<String> wrongVersionHelpAttr = new ArrayList<String>(); List<String> usageHelpAttr = new ArrayList<String>(); List<String> versionHelpAttr = new ArrayList<String>(); for (OptionSpec option : options()) { if (option.usageHelp()) { usageHelpAttr.add(option.longestName()); if (!isBoolean(option.type())) { wrongUsageHelpAttr.add(option.longestName()); } } if (option.versionHelp()) { versionHelpAttr.add(option.longestName()); if (!isBoolean(option.type())) { wrongVersionHelpAttr.add(option.longestName()); } } } String wrongType = "Non-boolean options like %s should not be marked as '%s=true'. Usually a command has one %s boolean flag that triggers display of the %s. Alternatively, consider using @Command(mixinStandardHelpOptions = true) on your command instead."; String multiple = "Multiple options %s are marked as '%s=true'. Usually a command has only one %s option that triggers display of the %s. Alternatively, consider using @Command(mixinStandardHelpOptions = true) on your command instead.%n"; if (!wrongUsageHelpAttr.isEmpty()) { throw new InitializationException(String.format(wrongType, wrongUsageHelpAttr, "usageHelp", "--help", "usage help message")); } if (!wrongVersionHelpAttr.isEmpty()) { throw new InitializationException(String.format(wrongType, wrongVersionHelpAttr, "versionHelp", "--version", "version information")); } if (usageHelpAttr.size() > 1) { new Tracer().warn(multiple, usageHelpAttr, "usageHelp", "--help", "usage help message"); } if (versionHelpAttr.size() > 1) { new Tracer().warn(multiple, versionHelpAttr, "versionHelp", "--version", "version information"); } }
private static int getSysPropertyWidthOrDefault(int defaultWidth) { String userValue = System.getProperty("picocli.usage.width"); if (userValue == null) { return defaultWidth; } try { int width = Integer.parseInt(userValue); if (width < MINIMUM_USAGE_WIDTH) { new Tracer().warn("Invalid picocli.usage.width value %d. Using minimum usage width %d.%n", width, MINIMUM_USAGE_WIDTH); return MINIMUM_USAGE_WIDTH; } return width; } catch (NumberFormatException ex) { new Tracer().warn("Invalid picocli.usage.width value '%s'. Using usage width %d.%n", userValue, defaultWidth); return defaultWidth; } }
tracer.warn("Both '%s' and '%s' are valid option names in %s. Using '%s'...%n", arg, key, getCommandName(), arg); } else if (commandSpec.optionsMap().containsKey(key)) { paramAttachedToOption = true;
new Tracer().warn("Unbalanced quotes in [%s] for %s (value=%s)%n", temp, this, value); quotedValues.add(temp.toString()); temp.setLength(0); new Tracer().warn("Unable to respect quotes while splitting value %s for %s (unprocessed remainder: %s)%n", value, this, quotedValues); return value.split(splitRegex(), limit);
/** Ensures all attributes of this {@code CommandSpec} have a valid value; throws an {@link InitializationException} if this cannot be achieved. */ void validate() { Collections.sort(positionalParameters, new PositionalParametersSorter()); validatePositionalParameters(positionalParameters); List<String> wrongUsageHelpAttr = new ArrayList<String>(); List<String> wrongVersionHelpAttr = new ArrayList<String>(); List<String> usageHelpAttr = new ArrayList<String>(); List<String> versionHelpAttr = new ArrayList<String>(); for (OptionSpec option : options()) { if (option.usageHelp()) { usageHelpAttr.add(option.longestName()); if (!isBoolean(option.type())) { wrongUsageHelpAttr.add(option.longestName()); } } if (option.versionHelp()) { versionHelpAttr.add(option.longestName()); if (!isBoolean(option.type())) { wrongVersionHelpAttr.add(option.longestName()); } } } String wrongType = "Non-boolean options like %s should not be marked as '%s=true'. Usually a command has one %s boolean flag that triggers display of the %s. Alternatively, consider using @Command(mixinStandardHelpOptions = true) on your command instead."; String multiple = "Multiple options %s are marked as '%s=true'. Usually a command has only one %s option that triggers display of the %s. Alternatively, consider using @Command(mixinStandardHelpOptions = true) on your command instead.%n"; if (!wrongUsageHelpAttr.isEmpty()) { throw new InitializationException(String.format(wrongType, wrongUsageHelpAttr, "usageHelp", "--help", "usage help message")); } if (!wrongVersionHelpAttr.isEmpty()) { throw new InitializationException(String.format(wrongType, wrongVersionHelpAttr, "versionHelp", "--version", "version information")); } if (usageHelpAttr.size() > 1) { new Tracer().warn(multiple, usageHelpAttr, "usageHelp", "--help", "usage help message"); } if (versionHelpAttr.size() > 1) { new Tracer().warn(multiple, versionHelpAttr, "versionHelp", "--version", "version information"); } }
private void clear(ArgSpec argSpec) { argSpec.resetStringValues(); argSpec.resetOriginalStringValues(); argSpec.typedValues.clear(); argSpec.typedValueAtPosition.clear(); if (argSpec.hasInitialValue()) { try { argSpec.setter().set(argSpec.initialValue()); tracer.debug("Set initial value for %s of type %s to %s.%n", argSpec, argSpec.type(), String.valueOf(argSpec.initialValue())); } catch (Exception ex) { tracer.warn("Could not set initial value for %s of type %s to %s: %s%n", argSpec, argSpec.type(), String.valueOf(argSpec.initialValue()), ex); } } else { tracer.debug("Initial value not available for %s%n", argSpec); } } private void maybeThrow(PicocliException ex) throws PicocliException {
private static int getSysPropertyWidthOrDefault(int defaultWidth) { String userValue = System.getProperty("picocli.usage.width"); if (userValue == null) { return defaultWidth; } try { int width = Integer.parseInt(userValue); if (width < MINIMUM_USAGE_WIDTH) { new Tracer().warn("Invalid picocli.usage.width value %d. Using minimum usage width %d.%n", width, MINIMUM_USAGE_WIDTH); return MINIMUM_USAGE_WIDTH; } return width; } catch (NumberFormatException ex) { new Tracer().warn("Invalid picocli.usage.width value '%s'. Using usage width %d.%n", userValue, defaultWidth); return defaultWidth; } }
tracer.warn("Both '%s' and '%s' are valid option names in %s. Using '%s'...%n", arg, key, getCommandName(), arg); } else if (commandSpec.optionsMap().containsKey(key)) { paramAttachedToOption = true;
private void clear(ArgSpec argSpec) { argSpec.resetStringValues(); argSpec.resetOriginalStringValues(); argSpec.typedValues.clear(); argSpec.typedValueAtPosition.clear(); if (argSpec.hasInitialValue()) { try { argSpec.setter().set(argSpec.initialValue()); tracer.debug("Set initial value for %s of type %s to %s.%n", argSpec, argSpec.type(), String.valueOf(argSpec.initialValue())); } catch (Exception ex) { tracer.warn("Could not set initial value for %s of type %s to %s: %s%n", argSpec, argSpec.type(), String.valueOf(argSpec.initialValue()), ex); } } else { tracer.debug("Initial value not available for %s%n", argSpec); } } private void maybeThrow(PicocliException ex) throws PicocliException {
private static String format(String formatString, Object... params) { try { return formatString == null ? "" : String.format(formatString, params); } catch (IllegalFormatException ex) { new Tracer().warn("Could not format '%s' (Underlying error: %s). " + "Using raw String: '%%n' format strings have not been replaced with newlines. " + "Please ensure to escape '%%' characters with another '%%'.%n", formatString, ex.getMessage()); return formatString; } }