public Text[][] render(PositionalParamSpec param, IParamLabelRenderer parameterLabelRenderer, ColorScheme scheme) { return new Text[][] {{ parameterLabelRenderer.renderParameterLabel(param, scheme.ansi(), scheme.parameterStyles), scheme.ansi().new Text(param.description().length == 0 ? "" : param.description()[0]) }}; } }
/** Returns the text displayed before the synopsis text; the result of {@code String.format(synopsisHeading, params)}. * @param params the parameters to use to format the synopsis heading * @return the formatted synopsis heading */ public String synopsisHeading(Object... params) { return heading(ansi(), width(), commandSpec.usageMessage().synopsisHeading(), params); }
/** * Returns the map of section keys and renderers used to construct the usage help message. * The usage help message can be customized by adding, replacing and removing section renderers from this map. * Sections can be reordered with {@link #setHelpSectionKeys(List) setSectionKeys}. * Sections that are either not in this map or not in the list returned by {@link #getHelpSectionKeys() getSectionKeys} are omitted. * <p> * NOTE: By modifying the returned {@code Map}, only the usage help message <em>of this command</em> is affected. * Use {@link #setHelpSectionMap(Map)} to customize the usage help message for this command <em>and all subcommands</em>. * </p> * @since 3.9 */ public Map<String, IHelpSectionRenderer> getHelpSectionMap() { return getCommandSpec().usageMessage().sectionMap(); }
/** * Helper class encapsulating the command line options and positional parameters. */ @Command(name = "java com.puppycrawl.tools.checkstyle.JavadocPropertiesGenerator", mixinStandardHelpOptions = true) private static class CliOptions { /** * The command line option to specify the output file. */ @Option(names = "--destfile", required = true, description = "The output file.") private File outputFile; /** * The command line positional parameter to specify the input file. */ @Parameters(index = "0", description = "The input file.") private File inputFile; } }
@Command public void doit(@Mixin CommonOption commonOptionParam, @Option(names = "-z") int z, @Parameters String arg0, String arg1) {}
@Option(names = "--minimum") public void setMinimum(int min) { if (min < 0) { throw new ParameterException(spec.commandLine(), "Minimum must be a positive integer"); } minimum = min; }
private void clear() { position = 0; endOfOptions = false; isHelpRequested = false; parseResult = ParseResult.builder(getCommandSpec()); for (OptionSpec option : getCommandSpec().options()) { clear(option); } for (PositionalParamSpec positional : getCommandSpec().positionalParameters()) { clear(positional); } } private void clear(ArgSpec argSpec) {
public Text[][] render(OptionSpec option, IParamLabelRenderer parameterLabelRenderer, ColorScheme scheme) { Text optionText = scheme.optionText(option.names()[0]); Text paramLabelText = parameterLabelRenderer.renderParameterLabel(option, scheme.ansi(), scheme.optionParamStyles); optionText = optionText.concat(paramLabelText); return new Text[][] {{ optionText, scheme.ansi().new Text(option.description().length == 0 ? "" : option.description()[0]) }}; } }
/** Returns whether arguments on the command line that resemble an option should be treated as positional parameters. * The default is {@code false} and the parser behaviour depends on {@link #isUnmatchedArgumentsAllowed()}. * @return {@code true} arguments on the command line that resemble an option should be treated as positional parameters, {@code false} otherwise * @see #getUnmatchedArguments() * @since 3.0 */ public boolean isUnmatchedOptionsArePositionalParams() { return getCommandSpec().parser().unmatchedOptionsArePositionalParams(); }
/** Returns the text displayed before the footer text; the result of {@code String.format(footerHeading, params)}. * @param params the parameters to use to format the footer heading * @return the formatted footer heading */ public String footerHeading(Object... params) { return heading(ansi(), width(), commandSpec.usageMessage().footerHeading(), params); } /** Returns a 2-column list with command names and the first line of their header or (if absent) description.
/** Returns whether to use a simplified argument file format that is compatible with JCommander. * In this format, every line (except empty lines and comment lines) * is interpreted as a single argument. Arguments containing whitespace do not need to be quoted. * When system property {@code "picocli.useSimplifiedAtFiles"} is defined, the system property value overrides the programmatically set value. * @return whether to use a simplified argument file format. The default is {@code false}. * @since 3.9 */ public boolean isUseSimplifiedAtFiles() { return getCommandSpec().parser().useSimplifiedAtFiles(); }
/** Returns whether the parser interprets the first positional parameter as "end of options" so the remaining * arguments are all treated as positional parameters. The default is {@code false}. * @return {@code true} if all values following the first positional parameter should be treated as positional parameters, {@code false} otherwise * @since 2.3 */ public boolean isStopAtPositional() { return getCommandSpec().parser().stopAtPositional(); }
/** Returns the {@code IHelpFactory} that is used to construct the usage help message. * @see #setHelpFactory(IHelpFactory) * @since 3.9 */ public IHelpFactory getHelpFactory() { return getCommandSpec().usageMessage().helpFactory(); }
/** Sets the command name (also called program name) displayed in the usage help synopsis to the specified value. * Note that this method only modifies the usage help message, it does not impact parsing behaviour. * The command name may also be set declaratively with the {@link CommandLine.Command#name()} annotation attribute. * @param commandName command name (also called program name) displayed in the usage help synopsis * @return this {@code CommandLine} object, to allow method chaining * @see CommandSpec#name(String) * @since 2.0 */ public CommandLine setCommandName(String commandName) { getCommandSpec().name(Assert.notNull(commandName, "commandName")); return this; }
private void setBundle(String bundleBaseName, ResourceBundle bundle) { usageMessage().messages(new Messages(this, bundleBaseName, bundle)); updateArgSpecMessages(); } private void updateArgSpecMessages() {
Builder(IAnnotatedElement source) { userObject = source.userObject(); setTypeInfo(source.getTypeInfo()); toString = source.getToString(); getter = source.getter(); setter = source.setter(); hasInitialValue = source.hasInitialValue(); try { initialValue = source.getter().get(); } catch (Exception ex) { initialValue = null; } } Builder(Option option, IAnnotatedElement source, IFactory factory) {
@Option(names = "--trex") void setTRexFences(final String value) { throw new ParameterException(spec.commandLine(), "TREX error"); } }
@Command(description = "Second level sub-subcommand 2") public static class Sub2Child2 { @Option(names = {"-u", "--timeUnit"}) private TimeUnit timeUnit; @Option(names = {"-t", "--timeout"}) private long timeout; @Parameters(completionCandidates = Candidates.class, description = "with candidates") String str2; }