if (!isAnyHelpRequested() && !required.isEmpty()) { for (ArgSpec missing : required) { if (missing.isOption()) { maybeThrow(MissingParameterException.create(CommandLine.this, required, config().separator())); } else {
String name = argSpec.isOption() ? ((OptionSpec) argSpec).longestName() : "position " + position; String prompt = String.format("Enter value for %s (%s): ", name, str(argSpec.renderedDescription(), 0)); if (tracer.isDebug()) {tracer.debug("Reading value for %s from console...%n", name);}
if (argSpec.isOption()) { maybeThrow(new MissingParameterException(CommandLine.this, argSpec, "Missing required parameter for " + optionDescription("", argSpec, 0)));
String name = argSpec.isOption() ? ((OptionSpec) argSpec).longestName() : "position " + position; String prompt = String.format("Enter value for %s (%s): ", name, str(argSpec.renderedDescription(), 0)); if (tracer.isDebug()) {tracer.debug("Reading value for %s from console...%n", name);}
private Range index(ArgSpec arg) { return arg.isOption() ? OPTION_INDEX : ((PositionalParamSpec) arg).index(); } }
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; }
/** Adds the specified {@code OptionSpec} or {@code PositionalParamSpec} to the list of options and parameters * that were matched on the command line. * @param arg the matched {@code OptionSpec} or {@code PositionalParamSpec} * @param position the command line position at which the {@code PositionalParamSpec} was matched. Ignored for {@code OptionSpec}s. * @return this builder for method chaining */ public Builder add(ArgSpec arg, int position) { if (arg.isOption()) { addOption((OptionSpec) arg); } else { addPositionalParam((PositionalParamSpec) arg, position); } return this; } /** Adds the specified {@code OptionSpec} to the list of options that were matched on the command line. */
/** Adds the specified option spec or positional parameter spec to the list of configured arguments to expect. * @param arg the option spec or positional parameter spec to add * @return this CommandSpec for method chaining */ public CommandSpec add(ArgSpec arg) { return arg.isOption() ? addOption((OptionSpec) arg) : addPositional((PositionalParamSpec) arg); }
@Override public String defaultValue(final ArgSpec argSpec) { loadConfigurationFromFile(); // only options can be used in config because a name is needed for the key // so we skip default for positional params return argSpec.isOption() ? getConfigurationValue(((OptionSpec) argSpec)) : null; }
private static String describe(ArgSpec argSpec, String separator) { String prefix = (argSpec.isOption()) ? ((OptionSpec) argSpec).longestName() + separator : "params[" + ((PositionalParamSpec) argSpec).index() + "]" + separator; return prefix + argSpec.paramLabel(); } }
private void updateHelpRequested(ArgSpec argSpec) { if (argSpec.isOption()) { OptionSpec option = (OptionSpec) argSpec; isHelpRequested |= is(argSpec, "help", option.help()); parseResult.versionHelpRequested |= is(argSpec, "versionHelp", option.versionHelp()); parseResult.usageHelpRequested |= is(argSpec, "usageHelp", option.usageHelp()); } } private boolean is(ArgSpec p, String attribute, boolean value) {
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); } String optionSeparator = argSpec.isOption() ? separator() : ""; if (capacity.min == 0) { // optional String sep2 = empty(optionSeparator.trim()) ? optionSeparator + "[" : "[" + optionSeparator;
if (argSpec.isOption()) { maybeThrow(new MissingParameterException(CommandLine.this, argSpec, "Missing required parameter for " + optionDescription("", argSpec, 0)));
private Range index(ArgSpec arg) { return arg.isOption() ? OPTION_INDEX : ((PositionalParamSpec) arg).index(); } }
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; }
/** Adds the specified {@code OptionSpec} or {@code PositionalParamSpec} to the list of options and parameters * that were matched on the command line. * @param arg the matched {@code OptionSpec} or {@code PositionalParamSpec} * @param position the command line position at which the {@code PositionalParamSpec} was matched. Ignored for {@code OptionSpec}s. * @return this builder for method chaining */ public Builder add(ArgSpec arg, int position) { if (arg.isOption()) { addOption((OptionSpec) arg); } else { addPositionalParam((PositionalParamSpec) arg, position); } return this; } /** Adds the specified {@code OptionSpec} to the list of options that were matched on the command line. */
/** Adds the specified option spec or positional parameter spec to the list of configured arguments to expect. * @param arg the option spec or positional parameter spec to add * @return this CommandSpec for method chaining */ public CommandSpec add(ArgSpec arg) { return arg.isOption() ? addOption((OptionSpec) arg) : addPositional((PositionalParamSpec) arg); }
private static String describe(ArgSpec argSpec, String separator) { String prefix = (argSpec.isOption()) ? ((OptionSpec) argSpec).longestName() + separator : "params[" + ((PositionalParamSpec) argSpec).index() + "]" + separator; return prefix + argSpec.paramLabel(); } }
private void updateHelpRequested(ArgSpec argSpec) { if (!parseResult.isInitializingDefaultValues && argSpec.isOption()) { OptionSpec option = (OptionSpec) argSpec; isHelpRequested |= is(argSpec, "help", option.help()); parseResult.versionHelpRequested |= is(argSpec, "versionHelp", option.versionHelp()); parseResult.usageHelpRequested |= is(argSpec, "usageHelp", option.usageHelp()); } } private boolean is(ArgSpec p, String attribute, boolean value) {