CommandLine interpreter that uses reflection to initialize an annotated user object with values obtained from the command line arguments.
The full user manual is hosted at https://picocli.info.
An example that implements Callable and uses the CommandLine. convenience API to run in a single line of code:
@Command(name = "checksum", mixinStandardHelpOptions = true, version = "checksum 4.0",
description = "Prints the checksum (SHA-1 by default) of a file to STDOUT.")
class CheckSum implements Callable<Integer> {
@Parameters(index = "0", description = "The file whose checksum to calculate.")
private File file;
@Option(names = {"-a", "--algorithm"}, description = "MD5, SHA-1, SHA-256, ...")
private String algorithm = "SHA-1";
@Override
public Integer call() throws Exception { // your business logic goes here...
byte[] fileContents = Files.readAllBytes(file.toPath());
byte[] digest = MessageDigest.getInstance(algorithm).digest(fileContents);
System.out.printf("%0" + (digest.length*2) + "x%n", new BigInteger(1,digest));
return 0;
}
// CheckSum implements Callable, so parsing, error handling and handling user
// requests for usage help or version help can be done with one line of code.
public static void main(String[] args) {
int exitCode = new CommandLine(new CheckSum()).execute(args);
System.exit(exitCode);
}
}
Another example where the application calls parseArgs and takes responsibility
for error handling and checking whether the user requested help:
import static picocli.CommandLine.*;
@Command(mixinStandardHelpOptions = true, version = "v3.0.0",
header = "Encrypt FILE(s), or standard input, to standard output or to the output file.")
public class Encrypt {
@Parameters(description = "Any number of input files")
private List<File> files = new ArrayList<File>();
@Option(names = { "-o", "--out" }, description = "Output file (default: print to console)")
private File outputFile;
@Option(names = { "-v", "--verbose"}, description = "Verbose mode. Helpful for troubleshooting. Multiple -v options increase the verbosity.")
private boolean[] verbose;
}
Use CommandLine to initialize a user object as follows:
public static void main(String... args) {
Encrypt encrypt = new Encrypt();
try {
ParseResult parseResult = new CommandLine(encrypt).parseArgs(args);
if (!CommandLine.printHelpIfRequested(parseResult)) {
runProgram(encrypt);
}
} catch (ParameterException ex) { // command line arguments could not be parsed
System.err.println(ex.getMessage());
ex.getCommandLine().usage(System.err);
}
}
Invoke the above program with some command line arguments. The below are all equivalent:
--verbose --out=outfile in1 in2 --verbose --out outfile in1 in2 -v --out=outfile in1 in2 -v -o outfile in1 in2 -v -o=outfile in1 in2 -vo outfile in1 in2 -vo=outfile in1 in2 -v -ooutfile in1 in2 -vooutfile in1 in2
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| public abstract static class | CommandLine.AbstractHandler<
the return type of this handler R, The type of the handler subclass; for fluent API method chaining T extends CommandLine.
Deprecated
see Abstract superclass for execute(String.
IParseResultHandler2 and IExceptionHandler2 implementations.
|
| public abstract static class | CommandLine.AbstractParseResultHandler<R>Command line parse result handler that returns a value.
|
| public static @interface | CommandLine.ArgGroup
A |
| private static class | CommandLine.Assert
Utility class providing some defensive coding convenience methods. |
| pack-priv static class | |
| private static class | CommandLine.BuiltIn
Inner class to group the built-in |
| pack-priv static class | CommandLine.ColoredStackTraceWriter
Extends StringWriter to use ColorScheme. |
| public static @interface | CommandLine.Command
Annotate your class with |
| private static class | CommandLine.CosineSimilarity
Uses cosine similarity to find matches from a candidate set for a specified input. |
| public static class | CommandLine.DefaultExceptionHandler<R>
Deprecated
see Default exception handler that handles invalid user input by printing the exception message, followed by the usage
message for the command or subcommand whose input was invalid.
execute(String., getParameterExceptionHandler() and getExecutionExceptionHandler()
|
| private static class | |
| private static class | |
| public static class | CommandLine.DuplicateNameException
Exception indicating that multiple named elements have incorrectly used the same name. |
| public static class | CommandLine.DuplicateOptionAnnotationsException
Exception indicating that multiple fields have been annotated with the same Option name. |
| public static class | CommandLine.ExecutionException
Exception indicating a problem while invoking a command or subcommand. |
| public static class | CommandLine.ExitCode
Defines some exit codes used by picocli as default return values from the |
| public static class | CommandLine.Help
A collection of methods and inner classes that provide fine-grained control over the contents and layout of the usage help message to display to end users when help is requested or invalid input values were specified. |
| public static class | CommandLine.HelpCommand
Deprecated
as a consequence of Help command that can be installed as a subcommand on all application commands.
CommandLine.IHelpCommandInitializable being deprecated.
|
| public static interface | CommandLine.IDefaultValueProvider
Provides default value for a command. |
| public static interface | CommandLine.IExceptionHandler
Deprecated
see Represents a function that can handle a execute(String., IParameterExceptionHandler and IExecutionExceptionHandler
ParameterException that occurred while
parsing the command line arguments.
|
| public static interface | CommandLine.IExceptionHandler2<
the return type of this handler R>
Deprecated
see Classes implementing this interface know how to handle execute(String., IParameterExceptionHandler and IExecutionExceptionHandler
ParameterExceptions (usually from invalid user input)
and ExecutionExceptions that occurred while executing the Runnable or Callable command.
|
| public static interface | CommandLine.IExecutionExceptionHandler
Classes implementing this interface know how to handle Exceptions that occurred while executing the |
| public static interface | CommandLine.IExecutionStrategy
Implementations are responsible for "executing" the user input and returning an exit code. |
| public static interface | CommandLine.IExitCodeExceptionMapper
Interface that provides the appropriate exit code that will be returned from the |
| public static interface | CommandLine.IExitCodeGenerator
|
| public static interface | CommandLine.IFactory
Factory for instantiating classes that are registered declaratively with annotation attributes, like
|
| public static interface | CommandLine.IHelpCommandInitializable
Deprecated
use Help commands that provide usage help for other commands can implement this interface to be initialized with the information they need.
IHelpCommandInitializable2 instead
|
| public static interface | CommandLine.IHelpCommandInitializable2
Help commands that provide usage help for other commands can implement this interface to be initialized with the information they need. |
| public static interface | CommandLine.IHelpFactory
Creates the |
| public static interface | CommandLine.IHelpSectionRenderer
Renders a section of the usage help message. |
| public static interface | CommandLine.IModelTransformer
Provides a way to modify how the command model is built. |
| public static interface | CommandLine.INegatableOptionTransformer
Determines the option name transformation of negatable boolean options. |
| public static class | CommandLine.InitializationException
Exception indicating a problem during |
| private class | CommandLine.Interpreter
Helper class responsible for processing command line arguments. |
| public static interface | CommandLine.IParameterConsumer
Options or positional parameters can be assigned a |
| public static interface | CommandLine.IParameterExceptionHandler
Classes implementing this interface know how to handle |
| public static interface | CommandLine.IParameterPreprocessor
Options, positional parameters and commands can be assigned a |
| public static interface | CommandLine.IParseResultHandler
Deprecated
Use Represents a function that can process a List of IExecutionStrategy instead.
CommandLine objects resulting from successfully
parsing the command line arguments.
|
| public static interface | CommandLine.IParseResultHandler2<
the return type of this handler R>
Deprecated
use Represents a function that can process the IExecutionStrategy instead, see execute(String.
ParseResult object resulting from successfully
parsing the command line arguments.
|
| public static interface | CommandLine.ITypeConverter<
the type of the object that is the result of the conversion K>
When parsing command line arguments and initializing
fields annotated with |
| public static interface | CommandLine.IVersionProvider
Provides version information for a command. |
| private static enum | |
| public static class | CommandLine.MaxValuesExceededException
Exception indicating that more values were specified for an option or parameter than its |
| public static class | CommandLine.MissingParameterException
Exception indicating that a required parameter was not specified. |
| public static class | CommandLine.MissingTypeConverterException
Exception indicating that an annotated field had a type for which no |
| public static @interface | CommandLine.Mixin
Fields annotated with |
| public static class | CommandLine.Model
This class provides a namespace for classes and interfaces that model concepts and attributes of command line interfaces in picocli. |
| public static class | CommandLine.MutuallyExclusiveArgsException
Exception indicating that the user input included multiple arguments from a mutually exclusive group. |
| private static class | |
| private static class | |
| private static class | |
| private static class | |
| private static class | |
| private static class | |
| public static @interface | CommandLine.Option
Annotate fields in your class with |
| public static class | CommandLine.OverwrittenOptionException
Exception indicating that an option for a single-value option field has been specified multiple times on the command line. |
| public static class | CommandLine.ParameterException
Exception indicating something went wrong while parsing command line options. |
| public static class | CommandLine.ParameterIndexGapException
Exception indicating that there was a gap in the indices of the fields annotated with |
| public static @interface | CommandLine.Parameters
Fields annotated with |
| public static @interface | CommandLine.ParentCommand
Fields annotated with |
| public static class | CommandLine.ParseResult
Encapsulates the result of parsing an array of command line arguments. |
| public static class | CommandLine.PicocliException
Base class of all exceptions thrown by |
| pack-priv static class | |
| public static class | CommandLine.PropertiesDefaultProvider
|
| public static class | CommandLine.Range
Describes the number of parameters required and accepted by an option or a positional parameter. |
| public static class | CommandLine.RegexTransformer
A regular expression-based option name transformation for negatable options. |
| public static class | CommandLine.RunAll
Deprecated
as a consequence of Command line execution strategy that prints help if requested, and otherwise executes the top-level command and
all subcommands as CommandLine.AbstractParseResultHandler and CommandLine.IParseResultHandler being deprecated.
Runnable, Callable or Method.
|
| public static class | CommandLine.RunFirst
Deprecated
as a consequence of Command line execution strategy that prints help if requested, and otherwise executes the top-level
CommandLine.AbstractParseResultHandler and CommandLine.IParseResultHandler being deprecated.
Runnable or Callable command.
|
| public static class | CommandLine.RunLast
Deprecated
as a consequence of Command line execution strategy that prints help if requested, and otherwise executes the most specific
CommandLine.AbstractParseResultHandler and CommandLine.IParseResultHandler being deprecated.
Runnable or Callable subcommand.
|
| public static enum | CommandLine.ScopeType
Specifies the scope of the element. |
| public static @interface | CommandLine.Spec
Fields annotated with |
| public static enum | CommandLine.TraceLevel
Enumerates over the trace level values for filtering which internal debug statements should be printed. |
| public static class | CommandLine.Tracer
Utility class for printing internal debug statements. |
| public static class | CommandLine.TypeConversionException
Exception thrown by |
| public static @interface | CommandLine.Unmatched
Fields annotated with |
| public static class | CommandLine.UnmatchedArgumentException
Exception indicating that a command line argument could not be mapped to any of the fields annotated with
|
| public static class | CommandLine.UseDefaultConverter
Converter that can be used to signal to picocli that it should use the default converter. |
| Modifier and Type | Field and Description |
|---|---|
| private CommandLine. | |
| private CommandLine. | |
| private PrintWriter | |
| private CommandLine. | |
| private Object | |
| private CommandLine. | |
| private CommandLine. | |
| private final CommandLine. | |
| private final CommandLine. | |
| private PrintWriter | |
| private CommandLine. | |
| private static final CommandLine. | |
| public static final String | VERSION
This is picocli version 4.7.5. |
| Access | Constructor and Description |
|---|---|
| public | CommandLine(Object
an annotated user object or a command)CommandSpec object to initialize from the command line argumentsConstructs a new |
| public | CommandLine(Object
an annotated user object or a command, CommandLine.CommandSpec object to initialize from the command line argumentsthe factory used to create instances of subcommands, converters, etc., that are registered declaratively with annotation attributes factoryConstructs a new |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public CommandLine | Returns: this CommandLine object, to allow method chainingthe name by which the mixin object may later be retrieved name, Object an annotated user object or a mixin)CommandSpec object whose options and positional parameters to add to this commandAdds the options and positional parameters in the specified mixin to this command. |
| public CommandLine | Returns: this CommandLine object, to allow method chainingthe object to initialize with command line arguments following the subcommand name.
This may be a command)Class that has a @Command annotation, or an instance of such a
class, or a CommandSpec or CommandLine instance with its own (nested) subcommands.Registers a subcommand with the name obtained from the |
| public CommandLine | Returns: this CommandLine object, to allow method chainingthe object to initialize with command line arguments following the subcommand name.
This may be a command)Class that has a @Command annotation, or an instance of such a
class, or a CommandSpec or CommandLine instance with its own (nested) subcommands.Registers a subcommand with the specified name. |
| public CommandLine | Returns: this CommandLine object, to allow method chainingthe object to initialize with command line arguments following the subcommand name.
This may be a command, String... Class that has a @Command annotation, or an instance of such a
class, or a CommandSpec or CommandLine instance with its own (nested) subcommands.zero or more alias names that are also recognized on the command line as this subcommand aliases)Registers a subcommand with the specified name and all specified aliases. |
| pack-priv static <K, T> void | |
| private void | |
| public static < the annotated object must implement Callable C extends Callablethe return type of the most specific command (must implement T> TCallable) | Returns: null if an error occurred while parsing the command line options, or if help was requested and printed. Otherwise returns the result of calling the Callablethe command to call when parsing succeeds. callable, String... the command line arguments to parse args)
Deprecated
use
Equivalent to execute(String. and getExecutionResult() instead
new CommandLine(callable).execute(args), except for the return value.
|
| public static < the annotated object must implement Callable C extends Callablethe return type of the most specific command (must implement T> TCallable) | Returns: null if an error occurred while parsing the command line options, or if help was requested and printed. Otherwise returns the result of calling the Callablethe command to call when parsing succeeds. callable, PrintStream the printStream to print the usage help message to when the user requested help out, String... the command line arguments to parse args)
Deprecated
use
Delegates to execute(String. and getExecutionResult() instead
call(Callable, PrintStream, PrintStream, Help. with System.err for
diagnostic error messages and Help..
|
| public static < the annotated object must implement Callable C extends Callablethe return type of the most specific command (must implement T> TCallable) | Returns: null if an error occurred while parsing the command line options, or if help was requested and printed. Otherwise returns the result of calling the Callablethe command to call when parsing succeeds. callable, PrintStream the printStream to print the usage help message to when the user requested help out, CommandLine.the ANSI style to use ansi,the command line arguments to parse args)
Deprecated
use
Delegates to execute(String. and getExecutionResult() instead
call(Callable, PrintStream, PrintStream, Help. with System.err for diagnostic error messages.
|
| public static < the annotated object must implement Callable C extends Callablethe return type of the specified T> TCallable | Returns: null if an error occurred while parsing the command line options, or if help was requested and printed. Otherwise returns the result of calling the Callablethe command to call when parsing succeeds. callable, PrintStream the printStream to print the usage help message to when the user requested help out, PrintStream the printStream to print diagnostic messages to err, CommandLine.including whether the usage message should include ANSI escape codes or not ansi,the command line arguments to parse args)
Deprecated
use
Convenience method to allow command line application authors to avoid some boilerplate code in their application.
execute(String. and getExecutionResult() instead
|
| public static < the annotated class must implement Callable C extends Callablethe return type of the most specific command (must implement T> TCallable) | Returns: null if an error occurred while parsing the command line options, or if help was requested and printed. Otherwise returns the result of calling the Callableclass of the command to call when parsing succeeds. callableClass, CommandLine.the factory responsible for instantiating the specified callable class and potentially inject other components factory,the command line arguments to parse args)
Deprecated
use
Equivalent to execute(String. and getExecutionResult() instead
new CommandLine(callableClass, factory).execute(args), except for the return value.
|
| public static < the annotated class must implement Callable C extends Callablethe return type of the most specific command (must implement T> TCallable) | Returns: null if an error occurred while parsing the command line options, or if help was requested and printed. Otherwise returns the result of calling the Callableclass of the command to call when parsing succeeds. callableClass, CommandLine.the factory responsible for instantiating the specified callable class and potentially injecting other components factory,the printStream to print the usage help message to when the user requested help out, String... the command line arguments to parse args)
Deprecated
use
Delegates to execute(String. and getExecutionResult() instead
call(Class, IFactory, PrintStream, PrintStream, Help. with
System.err for diagnostic error messages, and Help..
|
| public static < the annotated class must implement Callable C extends Callablethe return type of the most specific command (must implement T> TCallable) | Returns: null if an error occurred while parsing the command line options, or if help was requested and printed. Otherwise returns the result of calling the Callableclass of the command to call when parsing succeeds. callableClass, CommandLine.the factory responsible for instantiating the specified callable class and potentially injecting other components factory,the printStream to print the usage help message to when the user requested help out, CommandLine.the ANSI style to use ansi,the command line arguments to parse args)
Deprecated
use
Delegates to execute(String. and getExecutionResult() instead
call(Class, IFactory, PrintStream, PrintStream, Help. with
System.err for diagnostic error messages.
|
| public static < the annotated class must implement Callable C extends Callablethe return type of the most specific command (must implement T> TCallable) | Returns: null if an error occurred while parsing the command line options, or if help was requested and printed. Otherwise returns the result of calling the Callableclass of the command to call when parsing succeeds. callableClass, CommandLine.the factory responsible for instantiating the specified callable class and potentially injecting other components factory,the printStream to print the usage help message to when the user requested help out, PrintStream the printStream to print diagnostic messages to err, CommandLine.the ANSI style to use ansi,the command line arguments to parse args)
Deprecated
use
Convenience method to allow command line application authors to avoid some boilerplate code in their application.
execute(String. and getExecutionResult() instead
|
| pack-priv static Charset | |
| public void | clearExecutionResults()
Clears the execution result of a previous invocation from this |
| pack-priv static void | |
| private CommandLine | |
| private static Stack | |
| private static String | createMissingParameterMessage(CommandLine.
|
| public static CommandLine. | defaultExceptionHandler()
Deprecated
as a consequence of
Convenience method that returns CommandLine.DefaultExceptionHandler being deprecated.
new DefaultExceptionHandler<List<Object>>().
|
| public static CommandLine. | defaultFactory()
Returns the default |
| private static boolean | |
| private static boolean | |
| private <T> T | |
| public int | |
| public static Integer | Returns: CommandSpec#exitCodeOnUsageHelp() if usage help was requested,
CommandSpec#exitCodeOnVersionHelp() if version help was requested, and null otherwisecontains the parseResultCommandLine objects found during parsing; check these to see if help was requestedHelper method that may be useful when processing the |
| pack-priv static Integer | |
| private static List | |
| private static <T> T | |
| pack-priv static <T> List | |
| private static String | |
| public Character | Returns: the character that starts a single-line comment ornull. The default is '#'.Returns the character that starts a single-line comment or |
| public CommandLine. | |
| public < the type of the variable that the return value is being assigned to T> T | Returns: the annotated object that thisCommandLine instance was constructed withReturns the annotated user object that this |
| public static List | Returns: the matching command methods, or an empty listthe class to search for methods annotated with cls, String @Commandif not methodName)null, return only methods whose method name (not @Command.) equals this string. Ignored if null.Helper to get methods of a class annotated with |
| private static List | |
| public String | Returns: the command name (also called program name) displayed in the usageReturns the command name (also called program name) displayed in the usage help synopsis. |
| public CommandLine. | Returns: theCommandSpec modelReturns the |
| public CommandLine. | Returns: the default value provider for this command, ornullReturns the default value provider for the command, or |
| public String | Returns: the end-of-options delimiter. The default is"--".Returns the end-of-options delimiter that signals that the remaining command line arguments should be treated as positional parameters. |
| public PrintWriter | |
| public CommandLine. | Returns: the handler for dealing with exceptions that occurred in the business logic when theexecute method was invoked.Returns the handler for dealing with exceptions that occurred in the |
| public < type of the result value T> T | Returns: the result of the user objectCallable or Method (may be null), or null if this (sub)command was not executedReturns the result of calling the user object |
| public CommandLine. | Returns: the execution strategy to run the user-specified commandReturns the execution strategy used by the |
| public CommandLine. | getExitCodeExceptionMapper()
Returns the mapper that was set by the application to map from exceptions to exit codes, for use by the |
| public CommandLine. | Returns: the factory that thisCommandLine was constructed with, never nullReturns the factory that this |
| public CommandLine. | getHelp()
Returns a new |
| public CommandLine. | |
| public List | getHelpSectionKeys()
Returns the section keys in the order that the usage help message should render the sections. |
| public Map | getHelpSectionMap()
Returns the map of section keys and renderers used to construct the usage help message. |
| public Map | Returns: a new Map containing the user objects mixed in with this command. IfCommandSpec objects without
user objects were programmatically added, use the underlying model directly.Returns a map of user objects whose options and positional parameters were added to ("mixed in" with) this command. |
| public CommandLine. | Returns: theINegatableOptionTransformer used to create negative option names.Returns the |
| private static Object | |
| private static Object | |
| public PrintWriter | |
| public CommandLine. | Returns: the handler for dealing with invalid user inputReturns the handler for dealing with invalid user input when the command is executed. |
| public CommandLine | Returns: the command that this is a subcommand of, ornull if this is a top-level commandReturns the command that this is a subcommand of, or |
| public CommandLine. | |
| public ResourceBundle | |
| public String | Returns: the String the parser uses to separate option names from option valuesReturns the String that separates option names from option values when parsing command line options. |
| pack-priv static Charset | |
| pack-priv static Charset | |
| public Map | Returns: a map with the registered subcommandsReturns a map with the subcommands registered on this instance. |
| public List | Returns: the list of unmatched command line arguments or an empty listReturns the list of unmatched command line arguments, if any. |
| public int | getUsageHelpLongOptionsMaxWidth()
Returns the maximum usage help long options column max width to the specified value. |
| public int | |
| public String | getUsageMessage()
Similar to |
| public String | getUsageMessage(CommandLine.
Similar to |
| public String | getUsageMessage(CommandLine.
Similar to |
| private static int | |
| public static Object | invoke(String methodName, Class<?>
the class where the cls, String... @Command-annotated method is declared, or a subclassthe command line arguments to parse args)
Deprecated
use
Delegates to execute(String. and getExecutionResult() instead
invoke(String, Class, PrintStream, PrintStream, Help. with System.out for
requested usage help messages, System.err for diagnostic error messages, and Help..
|
| public static Object | invoke(String methodName, Class<?>
the class where the cls, PrintStream @Command-annotated method is declared, or a subclassthe printstream to print requested help message to out, String... the command line arguments to parse args)
Deprecated
use
Delegates to execute(String. and getExecutionResult() instead
invoke(String, Class, PrintStream, PrintStream, Help. with the specified stream for
requested usage help messages, System.err for diagnostic error messages, and Help..
|
| public static Object | invoke(String methodName, Class<?>
the class where the cls, PrintStream @Command-annotated method is declared, or a subclassthe printstream to print requested help message to out, CommandLine.whether the usage message should include ANSI escape codes or not ansi,the command line arguments to parse args)
Deprecated
use
Delegates to execute(String. and getExecutionResult() instead
invoke(String, Class, PrintStream, PrintStream, Help. with the specified stream for
requested usage help messages, System.err for diagnostic error messages, and the specified Ansi mode.
|
| public static Object | invoke(String methodName, Class<?>
the class where the cls, PrintStream @Command-annotated method is declared, or a subclassthe printStream to print the usage help message to when the user requested help out, PrintStream the printStream to print diagnostic messages to err, CommandLine.whether the usage message should include ANSI escape codes or not ansi,the command line arguments to parse args)
Deprecated
use
Convenience method to allow command line application authors to avoid some boilerplate code in their application.
execute(String. and getExecutionResult() instead
|
| public boolean | Returns: true if options can be matched when they are abbreviations of the names() value of a registered one, false otherwise.
For example, if true, for a subcommand with name --helpMe, inputs like --h, --h-m and --hM are all recognized.Returns whether abbreviation of option names should be allowed when matching options. |
| public boolean | Returns: true if subcommands can be matched when they are abbreviations of the getCommandName() value of a registered one, false otherwise.
For example, if true, for a subcommand with name helpCommand, inputs like h, h-c and hC are all recognized.Returns whether abbreviation of subcommands should be allowed when matching subcommands. |
| public boolean | Returns: true if wide Chinese, Japanese and Korean characters are counted as double the size of other characters for line-breaking purposesReturns whether line breaks should take wide Chinese, Japanese and Korean characters into account for line-breaking purposes. |
| public boolean | Returns: true when options can have parameter values that match the name of an option in this command, false when such values should be rejected with a missing parameter exceptionReturns whether options can have parameter values that match the name of an option in this command, or whether such values should be rejected with a missing parameter exception. |
| public boolean | Returns: true when options can have parameter values that match subcommand names or aliases, false when such values should be rejected with a missing parameter exceptionReturns whether options can have parameter values that match subcommand names or aliases, or whether such values should be rejected with a missing parameter exception. |
| private static boolean | |
| private static boolean | |
| public boolean | Returns: true if enum values can be specified that don't match the toString() value of the enum constant, false otherwise;
e.g., for an option of type java.time.DayOfWeek,
values MonDaY, monday and MONDAY are all recognized if true.Returns whether the parser should ignore case when converting arguments to |
| public boolean | Returns: whether "argument files" or@files should be expanded into their contentReturns whether arguments starting with |
| public boolean | |
| private static boolean | |
| private static boolean | |
| public boolean | Returns: true if options can be matched when they differ only in case from the names() value of a registered one, false otherwise;
For example, if true, for an option with name -h, inputs like -h, -H are both recognized.Returns whether upper case and lower case should be ignored when matching option names. |
| public boolean | Returns: true if options for single-value fields can be specified multiple times on the command line, false otherwiseReturns whether options for single-value fields can be specified multiple times on the command line. |
| public boolean | Returns: true if short options like -x -v -f SomeFile can be clustered together like -xvfSomeFile, false otherwiseReturns whether the parser accepts clustered short options. |
| public boolean | Returns: true if the parser is allowed to split quoted Strings, false otherwise;
Deprecated
Most applications should not change the default.
Returns whether the parser is allowed to split quoted Strings or not.
|
| public boolean | Returns: true if all values following the first positional parameter should be treated as positional parameters, false otherwiseReturns whether the parser interprets the first positional parameter as "end of options" so the remaining arguments are all treated as positional parameters. |
| public boolean | Returns: true when an unmatched option should result in the remaining command line arguments to be added to the
unmatchedArguments listReturns whether the parser should stop interpreting options and positional parameters as soon as it encounters an unmatched option. |
| public boolean | Returns: true if subcommands can be matched when they differ only in case from the getCommandName() value of a registered one, false otherwise.
For example, if true, for a subcommand with name help, inputs like help, HeLp and HELP are all recognized.Returns whether upper case and lower case should be ignored when matching subcommands. |
| public boolean | Returns: true the value of boolean flag options should be "toggled" when the option is matched, false otherwiseReturns whether the value of boolean flag options should be "toggled" when the option is matched. |
| public boolean | Returns: true if the parser should trim quotes from command line arguments before processing them, false otherwise;Returns whether the parser should trim quotes from command line arguments. |
| public boolean | Returns: true if the end use may specify unmatched arguments on the command line, false otherwiseReturns whether the end user may specify arguments on the command line that are not matched to any option or parameter fields. |
| public boolean | Returns: true when options can have parameter values that resemble an option, false when such values should be rejected as unknown optionsReturns whether options can have parameter values that resemble an option, or whether such values should be rejected as unknown options. |
| public boolean | Returns: true arguments on the command line that resemble an option should be treated as positional parameters, false otherwiseReturns whether arguments on the command line that resemble an option should be treated as positional parameters. |
| public boolean | isUsageHelpAutoWidth()
Returns whether picocli should attempt to detect the terminal size and adjust the usage help message width to take the full terminal width. |
| public boolean | Returns: whether the parser encountered an option annotated withOption#usageHelp().Returns |
| public boolean | Returns: whether to use a simplified argument file format. The default isfalse.Returns whether to use a simplified argument file format that is compatible with JCommander. |
| public boolean | Returns: whether the parser encountered an option annotated withOption#versionHelp().Returns |
| private static Map | |
| private static int | |
| pack-priv static PrintWriter | |
| private static String | |
| public List | Returns: a list with the top-level command and any subcommands initialized by this methodthe command line arguments to parse args)
Deprecated
use
Expands any @-files in the specified command line arguments, then
parses the arguments and returns a list of parseArgs(String. instead
CommandLine objects representing the
top-level command and any subcommands (if any) that were recognized and initialized during the parsing process.
|
| public CommandLine. | Returns: a list with the top-level command and any subcommands initialized by this methodthe command line arguments to parse args)Expands any @-files in the specified command line arguments, then
parses the arguments and returns a |
| public List | parseWithHandler(CommandLine.
Deprecated
use
execute(String. and getExecutionResult() instead
|
| public < the return type of this handler R> R | Returns: an object resulting from handling the parse result or the exception that occurred while parsing the inputthe function that will handle the result of successfully parsing the command line arguments handler,the command line arguments args)
Deprecated
use
Returns the result of calling execute(String. and getExecutionResult() instead
parseWithHandlers(IParseResultHandler2, IExceptionHandler2, String. with
a new DefaultExceptionHandler in addition to the specified parse result handler and the specified command line arguments.
|
| public List | parseWithHandlers(CommandLine.
Deprecated
use
execute(String. and getExecutionResult() instead
|
| public < the return type of the result handler and exception handler R> R | Returns: an object resulting from handling the parse result or the exception that occurred while parsing the inputthe function that will handle the result of successfully parsing the command line arguments handler,the function that can handle the exceptionHandler,ParameterException thrown when the command line arguments are invalidthe command line arguments args)
Deprecated
use
Tries to parse the specified command line arguments, and if successful, delegates
the processing of the resulting execute(String. and getExecutionResult() instead
ParseResult object to the specified handler.
|
| public static < the type of the annotated object T> T | Returns: the specified annotated objectthe object to initialize. This object contains fields annotated with
command, String... @Option or @Parameters.the command line arguments to parse args)Convenience method that initializes the specified annotated object from the specified command line arguments. |
| public static < the type of the annotated object T> T | Returns: an instance of the specified annotated interfacethe interface that defines the command specification. This object contains getter methods annotated with
spec, String... @Option or @Parameters.the command line arguments to parse args)Convenience method that derives the command specification from the specified interface class, and returns an instance of the specified interface. |
| public static boolean | printHelpIfRequested(List<CommandLine> parsedCommands, PrintStream out, CommandLine.
Deprecated
use
printHelpIfRequested(ParseResult) instead
|
| public static boolean | Returns: true if help was printed, false otherwisecontains the parseResultCommandLine objects found during parsing; check these to see if help was requestedDelegates to |
| public static boolean | Returns: true if help was printed, false otherwisethe list of parsedCommands, PrintStream CommandLine objects to check if help was requestedthe out, PrintStream PrintStream to print help to if requestedthe error string to print diagnostic messages to, in addition to the output from the exception handler err, CommandLine.for printing help messages using ANSI styles and colors ansi
Deprecated
use
Delegates to the implementation of executeHelpRequest(ParseResult) instead
executeHelpRequest(ParseResult).
|
| public static boolean | Returns: true if help was printed, false otherwisethe list of parsedCommands, PrintStream CommandLine objects to check if help was requestedthe out, PrintStream PrintStream to print help to if requestedthe error string to print diagnostic messages to, in addition to the output from the exception handler err, CommandLine.for printing help messages using ANSI styles and colors colorScheme
Deprecated
use
Delegates to the implementation of executeHelpRequest(ParseResult) instead
executeHelpRequest(ParseResult).
|
| public void | printVersionHelp(PrintStream
the printStream to print to out)Delegates to |
| public void | printVersionHelp(PrintStream
the printStream to print to out, CommandLine.whether the usage message should include ANSI escape codes or not ansiPrints version information from the |
| public void | printVersionHelp(PrintStream
the printStream to print to out, CommandLine.whether the usage message should include ANSI escape codes or not ansi,Arguments referenced by the format specifiers in the version strings params)Prints version information from the |
| public void | printVersionHelp(PrintWriter
the PrintWriter to print to out)Delegates to |
| public void | printVersionHelp(PrintWriter
the PrintWriter to print to out, CommandLine.whether the usage message should include ANSI escape codes or not ansi,Arguments referenced by the format specifiers in the version strings params)Prints version information from the |
| public < the target type K> CommandLine | Returns: this CommandLine object, to allow method chainingthe target class to convert parameter string values to cls, CommandLine.the class capable of converting string values to the specified target type converterRegisters the specified type converter for the specified class. |
| private static <T> Stack | |
| private static <T> T[] | |
| private static <T> List | |
| public static < the annotated object must implement Runnable R extends Runnable> void | run(R
the command to run when parsing succeeds. runnable, String... the command line arguments to parse args)
Deprecated
use
Equivalent to execute(String. instead
new CommandLine(runnable).execute(args).
|
| public static < the annotated object must implement Runnable R extends Runnable> void | run(R
the command to run when parsing succeeds. runnable, PrintStream the printStream to print the usage help message to when the user requested help out, String... the command line arguments to parse args)
Deprecated
use
Delegates to execute(String. instead
run(Runnable, PrintStream, PrintStream, Help. with System.err for diagnostic error messages and Help..
|
| public static < the annotated object must implement Runnable R extends Runnable> void | run(R
the command to run when parsing succeeds. runnable, PrintStream the printStream to print the usage help message to when the user requested help out, CommandLine.whether the usage message should include ANSI escape codes or not ansi,the command line arguments to parse args)
Deprecated
use
Delegates to execute(String. instead
run(Runnable, PrintStream, PrintStream, Help. with System.err for diagnostic error messages.
|
| public static < the annotated object must implement Runnable R extends Runnable> void | run(R
the command to run when parsing succeeds. runnable, PrintStream the printStream to print the usage help message to when the user requested help out, PrintStream the printStream to print diagnostic messages to err, CommandLine.whether the usage message should include ANSI escape codes or not ansi,the command line arguments to parse args)
Deprecated
use
Convenience method to allow command line application authors to avoid some boilerplate code in their application.
execute(String. instead
|
| public static < the annotated class must implement Runnable R extends Runnable> void | run(Class<R>
class of the command to run when parsing succeeds. runnableClass, CommandLine.the factory responsible for instantiating the specified Runnable class and potentially injecting other components factory,the command line arguments to parse args)
Deprecated
use
Equivalent to execute(String. instead
new CommandLine(runnableClass, factory).execute(args).
|
| public static < the annotated class must implement Runnable R extends Runnable> void | run(Class<R>
class of the command to run when parsing succeeds. runnableClass, CommandLine.the factory responsible for instantiating the specified Runnable class and potentially injecting other components factory,the printStream to print the usage help message to when the user requested help out, String... the command line arguments to parse args)
Deprecated
use
Delegates to execute(String. instead
run(Class, IFactory, PrintStream, PrintStream, Help. with
System.err for diagnostic error messages, and Help..
|
| public static < the annotated class must implement Runnable R extends Runnable> void | run(Class<R>
class of the command to run when parsing succeeds. runnableClass, CommandLine.the factory responsible for instantiating the specified Runnable class and potentially injecting other components factory,the printStream to print the usage help message to when the user requested help out, CommandLine.whether the usage message should include ANSI escape codes or not ansi,the command line arguments to parse args)
Deprecated
use
Delegates to execute(String. instead
run(Class, IFactory, PrintStream, PrintStream, Help. with
System.err for diagnostic error messages.
|
| public static < the annotated class must implement Runnable R extends Runnable> void | run(Class<R>
class of the command to run when parsing succeeds. runnableClass, CommandLine.the factory responsible for instantiating the specified Runnable class and potentially injecting other components factory,the printStream to print the usage help message to when the user requested help out, PrintStream the printStream to print diagnostic messages to err, CommandLine.whether the usage message should include ANSI escape codes or not ansi,the command line arguments to parse args)
Deprecated
use
Convenience method to allow command line application authors to avoid some boilerplate code in their application.
execute(String. instead
|
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting newValue)Sets whether abbreviated option names should be matched. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting newValue)Sets whether abbreviated subcommands should be matched. |
| public CommandLine | setAdjustLineBreaksForWideCJKCharacters(boolean
if true, wide Chinese, Japanese and Korean characters are counted as double the size of other characters for line-breaking purposes adjustForWideChars)Sets whether line breaks should take wide Chinese, Japanese and Korean characters into account, and returns this UsageMessageSpec. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting. When newValue)true, options can have parameter values that match the name of an option in this command, when false, such values are rejected with a missing parameter exceptionSets whether options can have parameter values that match the name of an option in this command, or whether such values should be rejected with a missing parameter exception. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting. When newValue)true, options can have parameter values that match subcommand names or aliases, when false, such values are rejected with a missing parameter exceptionSets whether options can have parameter values that match subcommand names or aliases, or whether such values should be rejected with a missing parameter exception. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe character that starts a single-line comment or atFileCommentChar)null. The default is '#'.Sets the character that starts a single-line comment or |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting newValue)Sets whether the parser should ignore case when converting arguments to |
| public CommandLine | setColorScheme(CommandLine.
the new color scheme colorSchemeSets the color scheme to use when printing help. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingcommand name (also called program name) displayed in the usage help synopsis commandName)Sets the command name (also called program name) displayed in the usage help synopsis to the specified value. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe default value provider to use newValueSets a default value provider for the command and sub-commands The specified setting will be registered with this |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe end-of-options delimiter; must not be delimiter)null. The default is "--".Sets the end-of-options delimiter that signals that the remaining command line arguments should be treated as positional parameters. |
| public CommandLine | Returns: this CommandLine for method chainingthe new PrintWriter to use err)Sets the writer to use when printing diagnostic (error) messages during command execution. |
| public CommandLine | Returns: this CommandLine for method chainingthe handler for dealing with exceptions that occurred in the business logic when the executionExceptionHandlerexecute method was invoked.Sets a custom handler for dealing with exceptions that occurred in the |
| public void | setExecutionResult(Object
the business logic result, may be result)nullSets the result of calling the business logic on the command's user object. |
| public CommandLine | Returns: this CommandLine for method chainingthe new execution strategy to run the user-specified command executionStrategySets the execution strategy that the |
| public CommandLine | Returns: this CommandLine for method chainingthe new value exitCodeExceptionMapperSets the mapper used by the |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingwhether "argument files" or expandAtFiles)@files should be expanded into their contentSets whether arguments starting with |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new help factory. Must be non- helpFactorynull.Sets a new |
| public CommandLine | setHelpSectionKeys(List<String> keys)
Sets the section keys in the order that the usage help message should render the sections. |
| public CommandLine | setHelpSectionMap(Map<String, CommandLine.
Sets the map of section keys and renderers used to construct the usage help message. |
| public CommandLine | setInterpolateVariables(boolean interpolate)
Sets whether variables should be interpolated in String values. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe transformerINegatableOptionTransformer used to create negative option names.Sets the |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting newValue)Sets whether upper case and lower case should be ignored when matching option names. |
| public CommandLine | Returns: this CommandLine for method chainingthe new PrintWriter to use out)Sets the writer to use when printing user-requested usage help or version help during command execution. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting newValue)Sets whether options for single-value fields can be specified multiple times on the command line without a |
| public CommandLine | Returns: this CommandLine for method chainingthe new handler for dealing with invalid user input parameterExceptionHandlerSets the handler for dealing with invalid user input when the command is executed. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting newValue)Sets whether short options like |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe ResourceBundle containing usage help message strings bundle)Sets the ResourceBundle containing usage help message strings. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe String that separates option names from option values separator)Sets the String the parser uses to separate option names from option values to the specified value. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting newValue)
Deprecated
Most applications should not change the default.
Sets whether the parser is allowed to split quoted Strings.
|
| public CommandLine | Returns: thisCommandLine object, to allow method chainingtrue if all values following the first positional parameter should be treated as positional parameters, false otherwiseSets whether the parser interprets the first positional parameter as "end of options" so the remaining arguments are all treated as positional parameters. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingtrue when an unmatched option should result in the remaining command line arguments to be added to the
unmatchedArguments listSets whether the parser should stop interpreting options and positional parameters as soon as it encounters an unmatched option. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting newValue)Sets whether upper case and lower case should be ignored when matching subcommands. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting newValue)Sets whether the value of boolean flag options should be "toggled" when the option is matched. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting newValue)Sets whether the parser should trim quotes from command line arguments before processing them. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting. When newValue)true, the last unmatched arguments are available via the getUnmatchedArguments() method.Sets whether the end user may specify unmatched arguments on the command line without a |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting. When newValue)true, options can have parameter values that resemble an option, when false, such values are rejected as unknown optionsSets whether options can have parameter values that resemble an option, or whether such values should be rejected as unknown options. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new setting. When newValue)true, arguments on the command line that resemble an option should be treated as positional parameters.Sets whether arguments on the command line that resemble an option should be treated as positional parameters. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingwhether picocli should attempt to detect the terminal size detectTerminalSize)Sets whether picocli should attempt to detect the terminal size and adjust the usage help message width to take the full terminal width. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe new maximum usage help long options column max width. Must be 20 or greater. columnWidth)Returns the maximum usage help long options column max width to the specified value. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingthe maximum width of the usage help message width)Sets the maximum width of the usage help message. |
| public CommandLine | Returns: thisCommandLine object, to allow method chainingwhether to use a simplified argument file format. The default is simplifiedAtFiles)false.Sets whether to use a simplified argument file format that is compatible with JCommander. |
| pack-priv static String | |
| pack-priv String | smartUnquoteIfEnabled(String value)
Return the unquoted value if the value contains no nested quotes, otherwise, return the value as is. |
| private static String | |
| private static String | Returns: converted and coloredStringthe t, CommandLine.Throwable to be convertedthe existingColorSchemeColorScheme to useConvert a |
| private static CommandLine | |
| public static CommandLine. | Returns: theTracer used internally for printing internal debug statementsReturns the |
| private static String | |
| public static void | usage(Object command, PrintStream
the print stream to print the help message to out)Equivalent to |
| public static void | usage(Object command, PrintStream
the print stream to print the help message to out, CommandLine.whether the usage message should contain ANSI escape codes or not ansiEquivalent to |
| public static void | usage(Object command, PrintStream
the print stream to print the help message to out, CommandLine.the colorSchemeColorScheme defining the styles for options, parameters and commands when ANSI is enabledEquivalent to |
| public void | usage(PrintStream
the printStream to print to out)Delegates to |
| public void | usage(PrintWriter
the PrintWriter to print to writer)Delegates to |
| public void | usage(PrintStream
the printStream to print to out, CommandLine.whether the usage message should include ANSI escape codes or not ansiDelegates to |
| public void | usage(PrintWriter writer, CommandLine.
Similar to |
| public void | usage(PrintStream
the out, CommandLine.PrintStream to print the usage help message tothe colorSchemeColorScheme defining the styles for options, parameters and commands when ANSI is enabledPrints a usage help message for the annotated command class to the specified |
| public void | usage(PrintWriter writer, CommandLine.
Similar to |
| private StringBuilder | |
| private static void | |
| pack-priv static String |