+All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
+
+Modifier and Type |
+Method and Description |
+
+
+CommandLine |
+addMixin(java.lang.String name,
+ java.lang.Object mixin)
+Adds the options and positional parameters in the specified mixin to this command.
+ |
+
+
+CommandLine |
+addSubcommand(java.lang.String name,
+ java.lang.Object command)
+Registers a subcommand with the specified name.
+ |
+
+
+CommandLine |
+addSubcommand(java.lang.String name,
+ java.lang.Object command,
+ java.lang.String... aliases)
+Registers a subcommand with the specified name and all specified aliases.
+ |
+
+
+static <C extends java.util.concurrent.Callable<T>,T> T |
+call(java.lang.Class<C> callableClass,
+ CommandLine.IFactory factory,
+ java.io.PrintStream out,
+ CommandLine.Help.Ansi ansi,
+ java.lang.String... args)
+
+ |
+
+
+static <C extends java.util.concurrent.Callable<T>,T> T |
+call(java.lang.Class<C> callableClass,
+ CommandLine.IFactory factory,
+ java.io.PrintStream out,
+ java.io.PrintStream err,
+ CommandLine.Help.Ansi ansi,
+ java.lang.String... args)
+Convenience method to allow command line application authors to avoid some boilerplate code in their application.
+ |
+
+
+static <C extends java.util.concurrent.Callable<T>,T> T |
+call(java.lang.Class<C> callableClass,
+ CommandLine.IFactory factory,
+ java.io.PrintStream out,
+ java.lang.String... args)
+
+ |
+
+
+static <C extends java.util.concurrent.Callable<T>,T> T |
+call(java.lang.Class<C> callableClass,
+ CommandLine.IFactory factory,
+ java.lang.String... args)
+
+ |
+
+
+static <C extends java.util.concurrent.Callable<T>,T> T |
+call(C callable,
+ java.io.PrintStream out,
+ CommandLine.Help.Ansi ansi,
+ java.lang.String... args)
+
+ |
+
+
+static <C extends java.util.concurrent.Callable<T>,T> T |
+call(C callable,
+ java.io.PrintStream out,
+ java.io.PrintStream err,
+ CommandLine.Help.Ansi ansi,
+ java.lang.String... args)
+Convenience method to allow command line application authors to avoid some boilerplate code in their application.
+ |
+
+
+static <C extends java.util.concurrent.Callable<T>,T> T |
+call(C callable,
+ java.io.PrintStream out,
+ java.lang.String... args)
+
+ |
+
+
+static <C extends java.util.concurrent.Callable<T>,T> T |
+call(C callable,
+ java.lang.String... args)
+
+ |
+
+
+static CommandLine.DefaultExceptionHandler<java.util.List<java.lang.Object>> |
+defaultExceptionHandler()
+Convenience method that returns new DefaultExceptionHandler<List<Object>>() .
+ |
+
+
+java.lang.Character |
+getAtFileCommentChar()
+Returns the character that starts a single-line comment or null if all content of argument files should
+ be interpreted as arguments (without comments).
+ |
+
+
+<T> T |
+getCommand()
+Returns the annotated user object that this CommandLine instance was constructed with.
+ |
+
+
+static java.util.List<java.lang.reflect.Method> |
+getCommandMethods(java.lang.Class<?> cls,
+ java.lang.String methodName)
+Helper to get methods of a class annotated with @Command via reflection, optionally filtered by method name (not @Command.name ).
+ |
+
+
+java.lang.String |
+getCommandName()
+Returns the command name (also called program name) displayed in the usage help synopsis.
+ |
+
+
+CommandLine.Model.CommandSpec |
+getCommandSpec()
+Returns the CommandSpec model that this CommandLine was constructed with.
+ |
+
+
+CommandLine.IDefaultValueProvider |
+getDefaultValueProvider()
+Returns the default value provider for the command, or null if none has been set.
+ |
+
+
+java.lang.String |
+getEndOfOptionsDelimiter()
+Returns the end-of-options delimiter that signals that the remaining command line arguments should be treated as positional parameters.
+ |
+
+
+CommandLine.IHelpFactory |
+getHelpFactory()
+Returns the IHelpFactory that is used to construct the usage help message.
+ |
+
+
+java.util.List<java.lang.String> |
+getHelpSectionKeys()
+Returns the section keys in the order that the usage help message should render the sections.
+ |
+
+
+java.util.Map<java.lang.String,CommandLine.IHelpSectionRenderer> |
+getHelpSectionMap()
+Returns the map of section keys and renderers used to construct the usage help message.
+ |
+
+
+java.util.Map<java.lang.String,java.lang.Object> |
+getMixins()
+Returns a map of user objects whose options and positional parameters were added to ("mixed in" with) this command.
+ |
+
+
+CommandLine |
+getParent()
+Returns the command that this is a subcommand of, or null if this is a top-level command.
+ |
+
+
+CommandLine.ParseResult |
+getParseResult() |
+
+
+java.util.ResourceBundle |
+getResourceBundle()
+Returns the ResourceBundle of this command or null if no resource bundle is set.
+ |
+
+
+java.lang.String |
+getSeparator()
+Returns the String that separates option names from option values when parsing command line options.
+ |
+
+
+java.util.Map<java.lang.String,CommandLine> |
+getSubcommands()
+Returns a map with the subcommands registered on this instance.
+ |
+
+
+java.util.List<java.lang.String> |
+getUnmatchedArguments()
+Returns the list of unmatched command line arguments, if any.
+ |
+
+
+int |
+getUsageHelpWidth()
+Returns the maximum width of the usage help message.
+ |
+
+
+java.lang.String |
+getUsageMessage()
+Similar to usage(PrintStream) , but returns the usage help message as a String instead of printing it to the PrintStream .
+ |
+
+
+java.lang.String |
+getUsageMessage(CommandLine.Help.Ansi ansi)
+
+ |
+
+
+java.lang.String |
+getUsageMessage(CommandLine.Help.ColorScheme colorScheme)
+
+ |
+
+
+static java.lang.Object |
+invoke(java.lang.String methodName,
+ java.lang.Class<?> cls,
+ java.io.PrintStream out,
+ CommandLine.Help.Ansi ansi,
+ java.lang.String... args)
+
+ |
+
+
+static java.lang.Object |
+invoke(java.lang.String methodName,
+ java.lang.Class<?> cls,
+ java.io.PrintStream out,
+ java.io.PrintStream err,
+ CommandLine.Help.Ansi ansi,
+ java.lang.String... args)
+Convenience method to allow command line application authors to avoid some boilerplate code in their application.
+ |
+
+
+static java.lang.Object |
+invoke(java.lang.String methodName,
+ java.lang.Class<?> cls,
+ java.io.PrintStream out,
+ java.lang.String... args)
+
+ |
+
+
+static java.lang.Object |
+invoke(java.lang.String methodName,
+ java.lang.Class<?> cls,
+ java.lang.String... args)
+
+ |
+
+
+boolean |
+isCaseInsensitiveEnumValuesAllowed()
+Returns whether the parser should ignore case when converting arguments to enum values.
+ |
+
+
+boolean |
+isExpandAtFiles()
+Returns whether arguments starting with '@' should be treated as the path to an argument file and its
+ contents should be expanded into separate arguments for each line in the specified file.
+ |
+
+
+boolean |
+isOverwrittenOptionsAllowed()
+Returns whether options for single-value fields can be specified multiple times on the command line.
+ |
+
+
+boolean |
+isPosixClusteredShortOptionsAllowed()
+Returns whether the parser accepts clustered short options.
+ |
+
+
+boolean |
+isSplitQuotedStrings()
+Returns whether the parser is allowed to split quoted Strings or not.
+ |
+
+
+boolean |
+isStopAtPositional()
+Returns whether the parser interprets the first positional parameter as "end of options" so the remaining
+ arguments are all treated as positional parameters.
+ |
+
+
+boolean |
+isStopAtUnmatched()
+Returns whether the parser should stop interpreting options and positional parameters as soon as it encounters an
+ unmatched option.
+ |
+
+
+boolean |
+isToggleBooleanFlags()
+Returns whether the value of boolean flag options should be "toggled" when the option is matched.
+ |
+
+
+boolean |
+isTrimQuotes()
+Returns whether the parser should trim quotes from command line arguments before processing them.
+ |
+
+
+boolean |
+isUnmatchedArgumentsAllowed()
+Returns whether the end user may specify arguments on the command line that are not matched to any option or parameter fields.
+ |
+
+
+boolean |
+isUnmatchedOptionsArePositionalParams()
+Returns whether arguments on the command line that resemble an option should be treated as positional parameters.
+ |
+
+
+boolean |
+isUsageHelpRequested()
+
+ |
+
+
+boolean |
+isUseSimplifiedAtFiles()
+Returns whether to use a simplified argument file format that is compatible with JCommander.
+ |
+
+
+boolean |
+isVersionHelpRequested()
+
+ |
+
+
+java.util.List<CommandLine> |
+parse(java.lang.String... args)
+Parses the specified command line arguments and returns a list of CommandLine objects representing the
+ top-level command and any subcommands (if any) that were recognized and initialized during the parsing process.
+ |
+
+
+CommandLine.ParseResult |
+parseArgs(java.lang.String... args)
+Parses the specified command line arguments and returns a list of ParseResult with the options, positional
+ parameters, and subcommands (if any) that were recognized and initialized during the parsing process.
+ |
+
+
+<R> R |
+parseWithHandler(CommandLine.IParseResultHandler2<R> handler,
+ java.lang.String[] args)
+
+ |
+
+
+java.util.List<java.lang.Object> |
+parseWithHandler(CommandLine.IParseResultHandler handler,
+ java.io.PrintStream out,
+ java.lang.String... args)
+
+ |
+
+
+<R> R |
+parseWithHandlers(CommandLine.IParseResultHandler2<R> handler,
+ CommandLine.IExceptionHandler2<R> exceptionHandler,
+ java.lang.String... args)
+Tries to parse the specified command line arguments, and if successful, delegates
+ the processing of the resulting ParseResult object to the specified handler.
+ |
+
+
+java.util.List<java.lang.Object> |
+parseWithHandlers(CommandLine.IParseResultHandler handler,
+ java.io.PrintStream out,
+ CommandLine.Help.Ansi ansi,
+ CommandLine.IExceptionHandler exceptionHandler,
+ java.lang.String... args)
+
+ |
+
+
+static <T> T |
+populateCommand(T command,
+ java.lang.String... args)
+
+ Convenience method that initializes the specified annotated object from the specified command line arguments.
+ |
+
+
+static <T> T |
+populateSpec(java.lang.Class<T> spec,
+ java.lang.String... args)
+
+ Convenience method that derives the command specification from the specified interface class, and returns an
+ instance of the specified interface.
+ |
+
+
+static boolean |
+printHelpIfRequested(CommandLine.ParseResult parseResult)
+
+ |
+
+
+static boolean |
+printHelpIfRequested(java.util.List<CommandLine> parsedCommands,
+ java.io.PrintStream out,
+ CommandLine.Help.Ansi ansi)
+
+ |
+
+
+static boolean |
+printHelpIfRequested(java.util.List<CommandLine> parsedCommands,
+ java.io.PrintStream out,
+ java.io.PrintStream err,
+ CommandLine.Help.Ansi ansi)
+Helper method that may be useful when processing the list of CommandLine objects that result from successfully
+ parsing command line arguments.
+ |
+
+
+static boolean |
+printHelpIfRequested(java.util.List<CommandLine> parsedCommands,
+ java.io.PrintStream out,
+ java.io.PrintStream err,
+ CommandLine.Help.ColorScheme colorScheme)
+Helper method that may be useful when processing the list of CommandLine objects that result from successfully
+ parsing command line arguments.
+ |
+
+
+void |
+printVersionHelp(java.io.PrintStream out)
+
+ |
+
+
+void |
+printVersionHelp(java.io.PrintStream out,
+ CommandLine.Help.Ansi ansi)
+
+ |
+
+
+void |
+printVersionHelp(java.io.PrintStream out,
+ CommandLine.Help.Ansi ansi,
+ java.lang.Object... params)
+
+ |
+
+
+<K> CommandLine |
+registerConverter(java.lang.Class<K> cls,
+ CommandLine.ITypeConverter<K> converter)
+Registers the specified type converter for the specified class.
+ |
+
+
+static <R extends java.lang.Runnable> void |
+run(java.lang.Class<R> runnableClass,
+ CommandLine.IFactory factory,
+ java.io.PrintStream out,
+ CommandLine.Help.Ansi ansi,
+ java.lang.String... args)
+
+ |
+
+
+static <R extends java.lang.Runnable> void |
+run(java.lang.Class<R> runnableClass,
+ CommandLine.IFactory factory,
+ java.io.PrintStream out,
+ java.io.PrintStream err,
+ CommandLine.Help.Ansi ansi,
+ java.lang.String... args)
+Convenience method to allow command line application authors to avoid some boilerplate code in their application.
+ |
+
+
+static <R extends java.lang.Runnable> void |
+run(java.lang.Class<R> runnableClass,
+ CommandLine.IFactory factory,
+ java.io.PrintStream out,
+ java.lang.String... args)
+
+ |
+
+
+static <R extends java.lang.Runnable> void |
+run(java.lang.Class<R> runnableClass,
+ CommandLine.IFactory factory,
+ java.lang.String... args)
+
+ |
+
+
+static <R extends java.lang.Runnable> void |
+run(R runnable,
+ java.io.PrintStream out,
+ CommandLine.Help.Ansi ansi,
+ java.lang.String... args)
+
+ |
+
+
+static <R extends java.lang.Runnable> void |
+run(R runnable,
+ java.io.PrintStream out,
+ java.io.PrintStream err,
+ CommandLine.Help.Ansi ansi,
+ java.lang.String... args)
+Convenience method to allow command line application authors to avoid some boilerplate code in their application.
+ |
+
+
+static <R extends java.lang.Runnable> void |
+run(R runnable,
+ java.io.PrintStream out,
+ java.lang.String... args)
+
+ |
+
+
+static <R extends java.lang.Runnable> void |
+run(R runnable,
+ java.lang.String... args)
+
+ |
+
+
+CommandLine |
+setAtFileCommentChar(java.lang.Character atFileCommentChar)
+Sets the character that starts a single-line comment or null if all content of argument files should
+ be interpreted as arguments (without comments).
+ |
+
+
+CommandLine |
+setCaseInsensitiveEnumValuesAllowed(boolean newValue)
+Sets whether the parser should ignore case when converting arguments to enum values.
+ |
+
+
+CommandLine |
+setCommandName(java.lang.String commandName)
+Sets the command name (also called program name) displayed in the usage help synopsis to the specified value.
+ |
+
+
+CommandLine |
+setDefaultValueProvider(CommandLine.IDefaultValueProvider newValue)
+Sets a default value provider for the command and sub-commands
+ |
+
+
+CommandLine |
+setEndOfOptionsDelimiter(java.lang.String delimiter)
+Sets the end-of-options delimiter that signals that the remaining command line arguments should be treated as positional parameters.
+ |
+
+
+CommandLine |
+setExpandAtFiles(boolean expandAtFiles)
+Sets whether arguments starting with '@' should be treated as the path to an argument file and its
+ contents should be expanded into separate arguments for each line in the specified file.
+ |
+
+
+CommandLine |
+setHelpFactory(CommandLine.IHelpFactory helpFactory)
+Sets a new IHelpFactory to customize the usage help message.
+ |
+
+
+CommandLine |
+setHelpSectionKeys(java.util.List<java.lang.String> keys)
+Sets the section keys in the order that the usage help message should render the sections.
+ |
+
+
+CommandLine |
+setHelpSectionMap(java.util.Map<java.lang.String,CommandLine.IHelpSectionRenderer> map)
+Sets the map of section keys and renderers used to construct the usage help message.
+ |
+
+
+CommandLine |
+setOverwrittenOptionsAllowed(boolean newValue)
+
+ |
+
+
+CommandLine |
+setPosixClusteredShortOptionsAllowed(boolean newValue)
+Sets whether short options like -x -v -f SomeFile can be clustered together like -xvfSomeFile .
+ |
+
+
+CommandLine |
+setResourceBundle(java.util.ResourceBundle bundle)
+Sets the ResourceBundle containing usage help message strings.
+ |
+
+
+CommandLine |
+setSeparator(java.lang.String separator)
+Sets the String the parser uses to separate option names from option values to the specified value.
+ |
+
+
+CommandLine |
+setSplitQuotedStrings(boolean newValue)
+Sets whether the parser is allowed to split quoted Strings.
+ |
+
+
+CommandLine |
+setStopAtPositional(boolean newValue)
+Sets whether the parser interprets the first positional parameter as "end of options" so the remaining
+ arguments are all treated as positional parameters.
+ |
+
+
+CommandLine |
+setStopAtUnmatched(boolean newValue)
+Sets whether the parser should stop interpreting options and positional parameters as soon as it encounters an
+ unmatched option.
+ |
+
+
+CommandLine |
+setToggleBooleanFlags(boolean newValue)
+Sets whether the value of boolean flag options should be "toggled" when the option is matched.
+ |
+
+
+CommandLine |
+setTrimQuotes(boolean newValue)
+Sets whether the parser should trim quotes from command line arguments before processing them.
+ |
+
+
+CommandLine |
+setUnmatchedArgumentsAllowed(boolean newValue)
+
+ |
+
+
+CommandLine |
+setUnmatchedOptionsArePositionalParams(boolean newValue)
+Sets whether arguments on the command line that resemble an option should be treated as positional parameters.
+ |
+
+
+CommandLine |
+setUsageHelpWidth(int width)
+Sets the maximum width of the usage help message.
+ |
+
+
+CommandLine |
+setUseSimplifiedAtFiles(boolean simplifiedAtFiles)
+Sets whether to use a simplified argument file format that is compatible with JCommander.
+ |
+
+
+static void |
+usage(java.lang.Object command,
+ java.io.PrintStream out)
+Equivalent to new CommandLine(command).usage(out) .
+ |
+
+
+static void |
+usage(java.lang.Object command,
+ java.io.PrintStream out,
+ CommandLine.Help.Ansi ansi)
+Equivalent to new CommandLine(command).usage(out, ansi) .
+ |
+
+
+static void |
+usage(java.lang.Object command,
+ java.io.PrintStream out,
+ CommandLine.Help.ColorScheme colorScheme)
+Equivalent to new CommandLine(command).usage(out, colorScheme) .
+ |
+
+
+void |
+usage(java.io.PrintStream out)
+
+ |
+
+
+void |
+usage(java.io.PrintStream out,
+ CommandLine.Help.Ansi ansi)
+
+ |
+
+
+void |
+usage(java.io.PrintStream out,
+ CommandLine.Help.ColorScheme colorScheme)
+Prints a usage help message for the annotated command class to the specified PrintStream .
+ |
+
+
+void |
+usage(java.io.PrintWriter writer)
+
+ |
+
+
+void |
+usage(java.io.PrintWriter writer,
+ CommandLine.Help.Ansi ansi)
+
+ |
+
+
+void |
+usage(java.io.PrintWriter writer,
+ CommandLine.Help.ColorScheme colorScheme)
+
+ |
+
+
+