private void printArg(ArgSpec arg, PrintWriter pw, String indent) { pw.printf("%sdescription: %s%n", indent, Arrays.toString(arg.description())); pw.printf("%sdescriptionKey: '%s'%n", indent, arg.descriptionKey()); pw.printf("%stypeInfo: %s%n", indent, arg.typeInfo()); pw.printf("%sarity: %s%n", indent, arg.arity()); pw.printf("%ssplitRegex: '%s'%n", indent, arg.splitRegex()); pw.printf("%sinteractive: %s%n", indent, arg.interactive()); pw.printf("%srequired: %s%n", indent, arg.required()); pw.printf("%shidden: %s%n", indent, arg.hidden()); pw.printf("%shideParamSyntax: %s%n", indent, arg.hideParamSyntax()); pw.printf("%sdefaultValue: '%s'%n", indent, arg.defaultValue()); pw.printf("%sshowDefaultValue: %s%n", indent, arg.showDefaultValue()); pw.printf("%shasInitialValue: %s%n", indent, arg.hasInitialValue()); pw.printf("%sinitialValue: '%s'%n", indent, arg.initialValue()); pw.printf("%sparamLabel: '%s'%n", indent, arg.paramLabel()); pw.printf("%sconverters: %s%n", indent, Arrays.toString(arg.converters())); pw.printf("%scompletionCandidates: %s%n", indent, iter(arg.completionCandidates())); pw.printf("%sgetter: %s%n", indent, arg.getter()); pw.printf("%ssetter: %s%n", indent, arg.setter()); }
private static Object findCompletionStartPoint(ParseResult parseResult) { List<Object> tentativeMatches = parseResult.tentativeMatch; for (int i = 1; i <= tentativeMatches.size(); i++) { Object found = tentativeMatches.get(tentativeMatches.size() - i); if (found instanceof CommandSpec) { return found; } if (found instanceof ArgSpec) { CommandLine.Range arity = ((ArgSpec) found).arity(); if (i < arity.min) { return found; // not all parameters have been supplied yet } else { return findCommandFor((ArgSpec) found, parseResult.commandSpec()); } } } return parseResult.commandSpec(); }
private void processStandaloneOption(Collection<ArgSpec> required, Set<ArgSpec> initialized, String arg, Stack<String> args, boolean paramAttachedToKey) throws Exception { ArgSpec argSpec = commandSpec.optionsMap().get(arg); required.remove(argSpec); Range arity = argSpec.arity(); if (paramAttachedToKey) { arity = arity.min(Math.max(1, arity.min)); // if key=value, minimum arity is at least 1 } LookBehind lookBehind = paramAttachedToKey ? LookBehind.ATTACHED_WITH_SEPARATOR : LookBehind.SEPARATE; if (tracer.isDebug()) {tracer.debug("Found option named '%s': %s, arity=%s%n", arg, argSpec, arity);} parseResult.nowProcessing.add(argSpec); applyOption(argSpec, lookBehind, arity, args, initialized, "option " + arg); }
boolean noMoreValues = args.isEmpty(); Range arity = argSpec.arity().isUnspecified ? derivedArity : argSpec.arity(); // #509 if (arity.max == 0 && !arity.isUnspecified && lookBehind == LookBehind.ATTACHED_WITH_SEPARATOR) { // #509 throw new MaxValuesExceededException(CommandLine.this, optionDescription("", argSpec, 0) +
public Text renderParameterLabel(ArgSpec argSpec, Ansi ansi, List<IStyle> styles) { Range capacity = argSpec.isOption() ? argSpec.arity() : ((PositionalParamSpec)argSpec).capacity(); if (capacity.max == 0) { return ansi.new Text(""); } if (argSpec.hideParamSyntax()) { return ansi.apply((argSpec.isOption() ? separator() : "") + argSpec.paramLabel(), styles); } if (!argSpec.arity().isVariable && argSpec.arity().min > 1) { result = ansi.new Text("(").concat(result).concat(")"); // repeating group
maybeThrow(MissingParameterException.create(CommandLine.this, required, config().separator())); } else { assertNoMissingParameters(missing, missing.arity(), argumentStack);
Range paramArity = argSpec.arity(); if (count > 1 || arity.min - available > 1) { msg += "s";
private static Object findCompletionStartPoint(ParseResult parseResult) { List<Object> tentativeMatches = parseResult.tentativeMatch; for (int i = 1; i <= tentativeMatches.size(); i++) { Object found = tentativeMatches.get(tentativeMatches.size() - i); if (found instanceof CommandSpec) { return found; } if (found instanceof ArgSpec) { CommandLine.Range arity = ((ArgSpec) found).arity(); if (i < arity.min) { return found; // not all parameters have been supplied yet } else { return findCommandFor((ArgSpec) found, parseResult.commandSpec()); } } } return parseResult.commandSpec(); }
private void processStandaloneOption(Collection<ArgSpec> required, Set<ArgSpec> initialized, String arg, Stack<String> args, boolean paramAttachedToKey) throws Exception { ArgSpec argSpec = commandSpec.optionsMap().get(arg); required.remove(argSpec); Range arity = argSpec.arity(); if (paramAttachedToKey) { arity = arity.min(Math.max(1, arity.min)); // if key=value, minimum arity is at least 1 } LookBehind lookBehind = paramAttachedToKey ? LookBehind.ATTACHED_WITH_SEPARATOR : LookBehind.SEPARATE; if (tracer.isDebug()) {tracer.debug("Found option named '%s': %s, arity=%s%n", arg, argSpec, arity);} parseResult.nowProcessing.add(argSpec); applyOption(argSpec, lookBehind, arity, args, initialized, "option " + arg); }
private String optionDescription(String prefix, ArgSpec argSpec, int index) { String desc = ""; if (argSpec.isOption()) { desc = prefix + "option '" + ((OptionSpec) argSpec).longestName() + "'"; if (index >= 0) { if (argSpec.arity().max > 1) { desc += " at index " + index; } desc += " (" + argSpec.paramLabel() + ")"; } } else { desc = prefix + "positional parameter at index " + ((PositionalParamSpec) argSpec).index() + " (" + argSpec.paramLabel() + ")"; } return desc; }
private void applyDefault(IDefaultValueProvider defaultValueProvider, ArgSpec arg, List<ArgSpec> required) throws Exception { // Default value provider return value is only used if provider exists and if value // is not null otherwise the original default or initial value are used String fromProvider = defaultValueProvider == null ? null : defaultValueProvider.defaultValue(arg); String defaultValue = fromProvider == null ? arg.defaultValue() : fromProvider; if (defaultValue == null) { return; } if (tracer.isDebug()) {tracer.debug("Applying defaultValue (%s) to %s%n", defaultValue, arg);} Range arity = arg.arity().min(Math.max(1, arg.arity().min)); applyOption(arg, LookBehind.SEPARATE, arity, stack(defaultValue), new HashSet<ArgSpec>(), arg.toString); required.remove(arg); }
boolean noMoreValues = args.isEmpty(); Range arity = argSpec.arity().isUnspecified ? derivedArity : argSpec.arity(); // #509 if (arity.max == 0 && !arity.isUnspecified && lookBehind == LookBehind.ATTACHED_WITH_SEPARATOR) { // #509 throw new MaxValuesExceededException(CommandLine.this, optionDescription("", argSpec, 0) +
if (cluster.length() > 0 && commandSpec.posixOptionsMap().containsKey(cluster.charAt(0))) { ArgSpec argSpec = commandSpec.posixOptionsMap().get(cluster.charAt(0)); Range arity = argSpec.arity(); String argDescription = "option " + prefix + cluster.charAt(0); if (tracer.isDebug()) {tracer.debug("Found option '%s%s' in %s: %s, arity=%s%n", prefix, cluster.charAt(0), arg,
public Text renderParameterLabel(ArgSpec argSpec, Ansi ansi, List<IStyle> styles) { Range capacity = argSpec.isOption() ? argSpec.arity() : ((PositionalParamSpec)argSpec).capacity(); if (capacity.max == 0) { return ansi.new Text(""); } if (argSpec.hideParamSyntax()) { return ansi.apply((argSpec.isOption() ? separator() : "") + argSpec.paramLabel(), styles); } if (!argSpec.arity().isVariable && argSpec.arity().min > 1) { result = ansi.new Text("(").concat(result).concat(")"); // repeating group
Range paramArity = argSpec.arity(); if (count > 1 || arity.min - available > 1) { msg += "s";
maybeThrow(MissingParameterException.create(CommandLine.this, required, config().separator())); } else { assertNoMissingParameters(missing, missing.arity(), argumentStack);
private String optionDescription(String prefix, ArgSpec argSpec, int index) { String desc = ""; if (argSpec.isOption()) { desc = prefix + "option '" + ((OptionSpec) argSpec).longestName() + "'"; if (index >= 0) { if (argSpec.arity().max > 1) { desc += " at index " + index; } desc += " (" + argSpec.paramLabel() + ")"; } } else { desc = prefix + "positional parameter at index " + ((PositionalParamSpec) argSpec).index() + " (" + argSpec.paramLabel() + ")"; } return desc; }
private void applyDefault(IDefaultValueProvider defaultValueProvider, ArgSpec arg, List<ArgSpec> required) throws Exception { // Default value provider return value is only used if provider exists and if value // is not null otherwise the original default or initial value are used String fromProvider = defaultValueProvider == null ? null : defaultValueProvider.defaultValue(arg); String defaultValue = fromProvider == null ? arg.defaultValue() : fromProvider; if (defaultValue == null) { return; } if (tracer.isDebug()) {tracer.debug("Applying defaultValue (%s) to %s%n", defaultValue, arg);} Range arity = arg.arity().min(Math.max(1, arg.arity().min)); applyOption(arg, LookBehind.SEPARATE, arity, stack(defaultValue), new HashSet<ArgSpec>(), arg.toString); required.remove(arg); }