Top Description Inners Fields Constructors Methods
picocli

public Class CommandLine

extends Object
Class Inheritance
Imports
java.io.*, java.lang.annotation.Annotation, .ElementType, .Retention, .RetentionPolicy, .Target, java.lang.reflect.*, java.math.BigDecimal, .BigInteger, java.net.InetAddress, .MalformedURLException, .NetworkInterface, .URI, .URISyntaxException, .URL, java.nio.ByteOrder, java.nio.charset.Charset, java.text.BreakIterator, .ParseException, .SimpleDateFormat, java.util.*, java.util.concurrent.Callable, java.util.concurrent.atomic.AtomicInteger, java.util.regex.Matcher, .Pattern, picocli.CommandLine.Help.Ansi.IStyle, .CommandLine.Help.Ansi.Style, .CommandLine.Help.Ansi.Text, picocli.CommandLine.Model.*, .CommandLine.ParseResult.GroupMatchContainer

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.

Example

An example that implements Callable and uses the CommandLine.execute 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

Classes and Interfaces for Defining a CommandSpec Model

Classes and Interfaces for Defining a CommandSpec Model

Classes Related to Parsing Command Line Arguments

Classes Related to Parsing Command Line Arguments

Nested and Inner Type Summary

Modifier and TypeClass 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.AbstractHandler<R, T>
>

Deprecated see execute(String...)
Abstract superclass for IParseResultHandler2 and IExceptionHandler2 implementations.
public abstract static class
public static @interface
CommandLine.ArgGroup

A Command may define one or more ArgGroups: a group of options, positional parameters or a mixture of the two.

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 ITypeConverter implementations.

pack-priv static class
CommandLine.ColoredStackTraceWriter

Extends StringWriter to use ColorScheme.

public static @interface
CommandLine.Command

Annotate your class with @Command when you want more control over the format of the generated help message.

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>

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.
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 execute and executeHelpRequest methods.

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 CommandLine.IHelpCommandInitializable being deprecated.
Help command that can be installed as a subcommand on all application commands.
public static interface
CommandLine.IDefaultValueProvider

Provides default value for a command.

public static interface
CommandLine.IExceptionHandler

Represents a function that can handle a ParameterException that occurred while parsing the command line arguments.
public static interface
CommandLine.IExceptionHandler2<
the return type of this handler
R
>

Classes implementing this interface know how to handle 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 Runnable, Callable or Method user object of the command.

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 execute method for an exception that occurred during parsing or while invoking the command's Runnable, Callable, or Method.

public static interface
CommandLine.IExitCodeGenerator

@Command-annotated classes can implement this interface to specify an exit code that will be returned from the execute method when the command is successfully invoked.

public static interface
CommandLine.IFactory

Factory for instantiating classes that are registered declaratively with annotation attributes, like Command#subcommands(), Option#converter(), Parameters#converter() and Command#versionProvider().

public static interface
CommandLine.IHelpCommandInitializable

Deprecated use IHelpCommandInitializable2 instead
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.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 Help instance used to render the usage help message.

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 CommandLine initialization.

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 IParameterConsumer that implements custom logic to process the parameters for this option or this position.

public static interface
CommandLine.IParameterExceptionHandler

Classes implementing this interface know how to handle ParameterExceptions (usually from invalid user input).

public static interface
CommandLine.IParameterPreprocessor

Options, positional parameters and commands can be assigned a IParameterPreprocessor that implements custom logic to preprocess the parameters for this option, position or command.

public static interface
CommandLine.IParseResultHandler

Deprecated Use IExecutionStrategy instead.
Represents a function that can process a List of CommandLine objects resulting from successfully parsing the command line arguments.
public static interface
CommandLine.IParseResultHandler2<
the return type of this handler
R
>

Deprecated use IExecutionStrategy instead, see execute(String...)
Represents a function that can process the 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 @Option or @Parameters, String values can be converted to any type for which a ITypeConverter is registered.

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 arity allows.

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 ITypeConverter was registered.

public static @interface
CommandLine.Mixin

Fields annotated with @Mixin are "expanded" into the current command: @Option and @Parameters in the mixin class are added to the options and positional parameters of this command.

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 @Option and picocli will initialize these fields when matching arguments are specified on the command line.

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 Parameters.

public static @interface
CommandLine.Parameters

Fields annotated with @Parameters will be initialized with positional parameters.

public static @interface
CommandLine.ParentCommand

Fields annotated with @ParentCommand will be initialized with the parent command of the current subcommand.

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 picocli.CommandLine.

pack-priv static class
public static class
CommandLine.PropertiesDefaultProvider

IDefaultValueProvider implementation that loads default values for command line options and positional parameters from a properties file or Properties object.

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 CommandLine.AbstractParseResultHandler and CommandLine.IParseResultHandler being deprecated.
Command line execution strategy that prints help if requested, and otherwise executes the top-level command and all subcommands as Runnable, Callable or Method.
public static class
CommandLine.RunFirst

Deprecated as a consequence of CommandLine.AbstractParseResultHandler and CommandLine.IParseResultHandler being deprecated.
Command line execution strategy that prints help if requested, and otherwise executes the top-level Runnable or Callable command.
public static class
CommandLine.RunLast

Deprecated as a consequence of CommandLine.AbstractParseResultHandler and CommandLine.IParseResultHandler being deprecated.
Command line execution strategy that prints help if requested, and otherwise executes the most specific Runnable or Callable subcommand.
public static enum
CommandLine.ScopeType

Specifies the scope of the element.

public static @interface
CommandLine.Spec

Fields annotated with @Spec will be initialized with the CommandSpec for the command the field is part of.

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 ITypeConverter implementations to indicate a String could not be converted.

public static @interface
CommandLine.Unmatched

Fields annotated with @Unmatched will be initialized with the list of unmatched command line arguments, if any.

public static class
CommandLine.UnmatchedArgumentException

Exception indicating that a command line argument could not be mapped to any of the fields annotated with Option or Parameters.

public static class
CommandLine.UseDefaultConverter

Converter that can be used to signal to picocli that it should use the default converter.

Field Summary

Modifier and TypeField and Description
private CommandLine.Help.ColorScheme
private CommandLine.Model.CommandSpec
private PrintWriter
private CommandLine.IExecutionExceptionHandler
private Object
private CommandLine.IExecutionStrategy
private CommandLine.IExitCodeExceptionMapper
private final CommandLine.IFactory
private final CommandLine.Interpreter
private PrintWriter
private CommandLine.IParameterExceptionHandler
private static final CommandLine.Tracer
public static final String
VERSION

This is picocli version 4.7.5.

Constructor Summary

AccessConstructor and Description
public
CommandLine(Object
an annotated user object or a CommandSpec object to initialize from the command line arguments
command
)

Constructs a new CommandLine interpreter with the specified object (which may be an annotated user object or a CommandSpec) and a default factory.

public
CommandLine(Object
an annotated user object or a CommandSpec object to initialize from the command line arguments
command
,
CommandLine.IFactory
the factory used to create instances of subcommands, converters, etc., that are registered declaratively with annotation attributes
factory
)

Constructs a new CommandLine interpreter with the specified object (which may be an annotated user object or a CommandSpec) and object factory.

private
CommandLine(Object command, CommandLine.IFactory factory, boolean userCalled)

Method Summary

Modifier and TypeMethod and Description
public CommandLine

Returns:

this CommandLine object, to allow method chaining
addMixin
(String
the name by which the mixin object may later be retrieved
name
,
Object
an annotated user object or a CommandSpec object whose options and positional parameters to add to this command
mixin
)

Adds the options and positional parameters in the specified mixin to this command.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
addSubcommand
(Object
the object to initialize with command line arguments following the subcommand name. This may be a Class that has a @Command annotation, or an instance of such a class, or a CommandSpec or CommandLine instance with its own (nested) subcommands.
command
)

Registers a subcommand with the name obtained from the @Command(name = "...") annotation attribute of the specified command.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
addSubcommand
(String
the string to recognize on the command line as a subcommand. If null, the name of the specified subcommand is used; if this is also null, the first alias is used.
name
,
Object
the object to initialize with command line arguments following the subcommand name. This may be a Class that has a @Command annotation, or an instance of such a class, or a CommandSpec or CommandLine instance with its own (nested) subcommands.
command
)

Registers a subcommand with the specified name.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
addSubcommand
(String
the string to recognize on the command line as a subcommand. If null, the name of the specified subcommand is used; if this is also null, the first alias is used.
name
,
Object
the object to initialize with command line arguments following the subcommand name. This may be a Class that has a @Command annotation, or an instance of such a class, or a CommandSpec or CommandLine instance with its own (nested) subcommands.
command
,
String...
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
addValueToListInMap(Map<K, List<T>> map, K key, T value)

private void
applyModelTransformations()

Apply transformers to command spec recursively.

public static <
the annotated object must implement Callable
C extends Callable<T>
,
the return type of the most specific command (must implement Callable)
T
>
T

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 Callable
call
(C
the command to call when parsing succeeds.
callable
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Equivalent to new CommandLine(callable).execute(args), except for the return value.
public static <
the annotated object must implement Callable
C extends Callable<T>
,
the return type of the most specific command (must implement Callable)
T
>
T

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 Callable
call
(C
the 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 execute(String...) and getExecutionResult() instead
Delegates to call(Callable, PrintStream, PrintStream, Help.Ansi, String...) with System.err for diagnostic error messages and Help.Ansi#AUTO.
public static <
the annotated object must implement Callable
C extends Callable<T>
,
the return type of the most specific command (must implement Callable)
T
>
T

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 Callable
call
(C
the command to call when parsing succeeds.
callable
,
PrintStream
the printStream to print the usage help message to when the user requested help
out
,
CommandLine.Help.Ansi
the ANSI style to use
ansi
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Delegates to call(Callable, PrintStream, PrintStream, Help.Ansi, String...) with System.err for diagnostic error messages.
public static <
the annotated object must implement Callable
C extends Callable<T>
,
the return type of the specified Callable
T
>
T

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 Callable
call
(C
the 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.Help.Ansi
including whether the usage message should include ANSI escape codes or not
ansi
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Convenience method to allow command line application authors to avoid some boilerplate code in their application.
public static <
the annotated class must implement Callable
C extends Callable<T>
,
the return type of the most specific command (must implement Callable)
T
>
T

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 Callable
call
(Class<C>
class of the command to call when parsing succeeds.
callableClass
,
CommandLine.IFactory
the factory responsible for instantiating the specified callable class and potentially inject other components
factory
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Equivalent to new CommandLine(callableClass, factory).execute(args), except for the return value.
public static <
the annotated class must implement Callable
C extends Callable<T>
,
the return type of the most specific command (must implement Callable)
T
>
T

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 Callable
call
(Class<C>
class of the command to call when parsing succeeds.
callableClass
,
CommandLine.IFactory
the factory responsible for instantiating the specified callable class and potentially injecting other components
factory
,
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 execute(String...) and getExecutionResult() instead
Delegates to call(Class, IFactory, PrintStream, PrintStream, Help.Ansi, String...) with System.err for diagnostic error messages, and Help.Ansi#AUTO.
public static <
the annotated class must implement Callable
C extends Callable<T>
,
the return type of the most specific command (must implement Callable)
T
>
T

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 Callable
call
(Class<C>
class of the command to call when parsing succeeds.
callableClass
,
CommandLine.IFactory
the factory responsible for instantiating the specified callable class and potentially injecting other components
factory
,
PrintStream
the printStream to print the usage help message to when the user requested help
out
,
CommandLine.Help.Ansi
the ANSI style to use
ansi
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Delegates to call(Class, IFactory, PrintStream, PrintStream, Help.Ansi, String...) with System.err for diagnostic error messages.
public static <
the annotated class must implement Callable
C extends Callable<T>
,
the return type of the most specific command (must implement Callable)
T
>
T

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 Callable
call
(Class<C>
class of the command to call when parsing succeeds.
callableClass
,
CommandLine.IFactory
the factory responsible for instantiating the specified callable class and potentially injecting other components
factory
,
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.Help.Ansi
the ANSI style to use
ansi
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Convenience method to allow command line application authors to avoid some boilerplate code in their application.
pack-priv static Charset
public void
clearExecutionResults()

Clears the execution result of a previous invocation from this CommandLine and all subcommands.

pack-priv static void
close(Closeable closeable)

private CommandLine
copy()

private static Stack<String>
copy(Stack<String> stack)

private static String
public static CommandLine.DefaultExceptionHandler<List<Object>>
defaultExceptionHandler()

Deprecated as a consequence of CommandLine.DefaultExceptionHandler being deprecated.
Convenience method that returns new DefaultExceptionHandler<List<Object>>().
public static CommandLine.IFactory
defaultFactory()

Returns the default IFactory implementation used if no factory was specified in the CommandLine constructor.

private static boolean
private static boolean
empty(Object[] array)

private <T> T
public int

Returns:

the exit code
execute
(String...
the command line arguments to parse
args
)

Convenience method to allow command line application authors to avoid some boilerplate code in their application.

public static Integer

Returns:

CommandSpec#exitCodeOnUsageHelp() if usage help was requested, CommandSpec#exitCodeOnVersionHelp() if version help was requested, and null otherwise
executeHelpRequest
(CommandLine.ParseResult
contains the CommandLine objects found during parsing; check these to see if help was requested
parseResult
)

Helper method that may be useful when processing the ParseResult that results from successfully parsing command line arguments.

pack-priv static Integer
private static List<Object>
executeUserObject(CommandLine parsed, List<Object> executionResultList)

private static <T> T
pack-priv static <T> List<T>
flatList(Collection<? extends Collection<T>> collection)

private static String
format(String formatString, Object... params)

public Character

Returns:

the character that starts a single-line comment or null. The default is '#'.
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).

public CommandLine.Help.ColorScheme
getColorScheme()

Returns the color scheme to use when printing help.

public <
the type of the variable that the return value is being assigned to
T
>
T

Returns:

the annotated object that this CommandLine instance was constructed with
getCommand
()

Returns the annotated user object that this CommandLine instance was constructed with.

public static List<Method>

Returns:

the matching command methods, or an empty list
getCommandMethods
(Class<?>
the class to search for methods annotated with @Command
cls
,
String
if not null, return only methods whose method name (not @Command.name) equals this string. Ignored if null.
methodName
)

Helper to get methods of a class annotated with @Command via reflection, optionally filtered by method name (not @Command.name).

private static List<Method>
getCommandMethods(Class<?> cls, String methodName, boolean includeInherited)

public String

Returns:

the command name (also called program name) displayed in the usage
getCommandName
()

Returns the command name (also called program name) displayed in the usage help synopsis.

public CommandLine.Model.CommandSpec

Returns:

the CommandSpec model
getCommandSpec
()

Returns the CommandSpec model that this CommandLine was constructed with.

public CommandLine.IDefaultValueProvider

Returns:

the default value provider for this command, or null
getDefaultValueProvider
()

Returns the default value provider for the command, or null if none has been set.

public String

Returns:

the end-of-options delimiter. The default is "--".
getEndOfOptionsDelimiter
()

Returns the end-of-options delimiter that signals that the remaining command line arguments should be treated as positional parameters.

public PrintWriter
getErr()

Returns the writer to use when printing diagnostic (error) messages during command execution.

public CommandLine.IExecutionExceptionHandler

Returns:

the handler for dealing with exceptions that occurred in the business logic when the execute method was invoked.
getExecutionExceptionHandler
()

Returns the handler for dealing with exceptions that occurred in the Callable, Runnable or Method user object of a command when the command was executed.

public <
type of the result value
T
>
T

Returns:

the result of the user object Callable or Method (may be null), or null if this (sub)command was not executed
getExecutionResult
()

Returns the result of calling the user object Callable or invoking the user object Method after parsing the user input, or null if this command has not been executed or if this CommandLine is for a subcommand that was not specified by the end user on the command line.

public CommandLine.IExecutionStrategy

Returns:

the execution strategy to run the user-specified command
getExecutionStrategy
()

Returns the execution strategy used by the execute method to invoke the business logic on the user objects of this command and/or the user-specified subcommand(s).

public CommandLine.IExitCodeExceptionMapper

Returns:

the mapper that was set, or null if none was set
getExitCodeExceptionMapper
()

Returns the mapper that was set by the application to map from exceptions to exit codes, for use by the execute method.

public CommandLine.IFactory

Returns:

the factory that this CommandLine was constructed with, never null
getFactory
()

Returns the factory that this CommandLine was constructed with.

public CommandLine.Help
getHelp()

Returns a new Help object created by the IHelpFactory with the CommandSpec and ColorScheme of this command.

public CommandLine.IHelpFactory
getHelpFactory()

Returns the IHelpFactory that is used to construct the usage help message.

public List<String>
getHelpSectionKeys()

Returns the section keys in the order that the usage help message should render the sections.

public Map<String, CommandLine.IHelpSectionRenderer>
getHelpSectionMap()

Returns the map of section keys and renderers used to construct the usage help message.

public Map<String, Object>

Returns:

a new Map containing the user objects mixed in with this command. If CommandSpec objects without user objects were programmatically added, use the underlying model directly.
getMixins
()

Returns a map of user objects whose options and positional parameters were added to ("mixed in" with) this command.

public CommandLine.INegatableOptionTransformer

Returns:

the INegatableOptionTransformer used to create negative option names.
getNegatableOptionTransformer
()

Returns the INegatableOptionTransformer used to create the negative form of negatable options.

private static Object
private static Object
public PrintWriter
getOut()

Returns the writer used when printing user-requested usage help or version help during command execution.

public CommandLine.IParameterExceptionHandler

Returns:

the handler for dealing with invalid user input
getParameterExceptionHandler
()

Returns the handler for dealing with invalid user input when the command is executed.

public CommandLine

Returns:

the command that this is a subcommand of, or null if this is a top-level command
getParent
()

Returns the command that this is a subcommand of, or null if this is a top-level command.

public CommandLine.ParseResult
public ResourceBundle
getResourceBundle()

Returns the ResourceBundle of this command or null if no resource bundle is set.

public String

Returns:

the String the parser uses to separate option names from option values
getSeparator
()

Returns the String that separates option names from option values when parsing command line options.

pack-priv static Charset
pack-priv static Charset
public Map<String, CommandLine>

Returns:

a map with the registered subcommands
getSubcommands
()

Returns a map with the subcommands registered on this instance.

public List<String>

Returns:

the list of unmatched command line arguments or an empty list
getUnmatchedArguments
()

Returns 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
getUsageHelpWidth()

Returns the maximum width of the usage help message.

public String
getUsageMessage()

Similar to usage(PrintStream), but returns the usage help message as a String instead of printing it to the PrintStream.

public String
getUsageMessage(CommandLine.Help.Ansi ansi)

Similar to usage(PrintStream, Help.Ansi), but returns the usage help message as a String instead of printing it to the PrintStream.

public String
getUsageMessage(CommandLine.Help.ColorScheme colorScheme)

Similar to usage(PrintStream, Help.ColorScheme), but returns the usage help message as a String instead of printing it to the PrintStream.

private static int
handleUnhandled(Exception ex, CommandLine cmd, int defaultExitCode)

public static Object
invoke(String
the @Command-annotated method to build a CommandSpec model from, and run when parsing succeeds.
methodName
,
Class<?>
the class where the @Command-annotated method is declared, or a subclass
cls
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Delegates to invoke(String, Class, PrintStream, PrintStream, Help.Ansi, String...) with System.out for requested usage help messages, System.err for diagnostic error messages, and Help.Ansi#AUTO.
public static Object
invoke(String
the @Command-annotated method to build a CommandSpec model from, and run when parsing succeeds.
methodName
,
Class<?>
the class where the @Command-annotated method is declared, or a subclass
cls
,
PrintStream
the printstream to print requested help message to
out
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Delegates to invoke(String, Class, PrintStream, PrintStream, Help.Ansi, String...) with the specified stream for requested usage help messages, System.err for diagnostic error messages, and Help.Ansi#AUTO.
public static Object
invoke(String
the @Command-annotated method to build a CommandSpec model from, and run when parsing succeeds.
methodName
,
Class<?>
the class where the @Command-annotated method is declared, or a subclass
cls
,
PrintStream
the printstream to print requested help message to
out
,
CommandLine.Help.Ansi
whether the usage message should include ANSI escape codes or not
ansi
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Delegates to invoke(String, Class, PrintStream, PrintStream, Help.Ansi, String...) 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
the @Command-annotated method to build a CommandSpec model from, and run when parsing succeeds.
methodName
,
Class<?>
the class where the @Command-annotated method is declared, or a subclass
cls
,
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.Help.Ansi
whether the usage message should include ANSI escape codes or not
ansi
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Convenience method to allow command line application authors to avoid some boilerplate code in their application.
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.
isAbbreviatedOptionsAllowed
()

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.
isAbbreviatedSubcommandsAllowed
()

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 purposes
isAdjustLineBreaksForWideCJKCharacters
()

Returns 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 exception
isAllowOptionsAsOptionParameters
()

Returns 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 exception
isAllowSubcommandsAsOptionParameters
()

Returns 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
isBoolean(Class<?>[] types)

private static boolean
isBoolean(Class<?> type)

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.
isCaseInsensitiveEnumValuesAllowed
()

Returns whether the parser should ignore case when converting arguments to enum values.

public boolean

Returns:

whether "argument files" or @files should be expanded into their content
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.

public boolean
isInterpolateVariables()

Returns whether variables should be interpolated in String values.

private static boolean
private static boolean
isOptional(Class<?> cls)

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.
isOptionsCaseInsensitive
()

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 otherwise
isOverwrittenOptionsAllowed
()

Returns 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 otherwise
isPosixClusteredShortOptionsAllowed
()

Returns whether the parser accepts clustered short options.

public boolean

Returns:

true if the parser is allowed to split quoted Strings, false otherwise;
isSplitQuotedStrings
()

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 otherwise
isStopAtPositional
()

Returns 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 list
isStopAtUnmatched
()

Returns 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.
isSubcommandsCaseInsensitive
()

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 otherwise
isToggleBooleanFlags
()

Returns 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;
isTrimQuotes
()

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 otherwise
isUnmatchedArgumentsAllowed
()

Returns 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 options
isUnmatchedOptionsAllowedAsOptionParameters
()

Returns 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 otherwise
isUnmatchedOptionsArePositionalParams
()

Returns 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 with Option#usageHelp().
isUsageHelpRequested
()

Returns true if an option annotated with Option#usageHelp() was specified on the command line.

public boolean

Returns:

whether to use a simplified argument file format. The default is false.
isUseSimplifiedAtFiles
()

Returns whether to use a simplified argument file format that is compatible with JCommander.

public boolean

Returns:

whether the parser encountered an option annotated with Option#versionHelp().
isVersionHelpRequested
()

Returns true if an option annotated with Option#versionHelp() was specified on the command line.

private static Map<String, Object>
mapOf(String key, Object value, Object... other)

private static int
pack-priv static PrintWriter
private static String
optionDescription(String prefix, CommandLine.Model.ArgSpec argSpec, int optionParamIndex)

public List<CommandLine>

Returns:

a list with the top-level command and any subcommands initialized by this method
parse
(String...
the command line arguments to parse
args
)

Deprecated use parseArgs(String...) instead
Expands any @-files in the specified command line arguments, then parses the 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.
public CommandLine.ParseResult

Returns:

a list with the top-level command and any subcommands initialized by this method
parseArgs
(String...
the command line arguments to parse
args
)

Expands any @-files in the specified command line arguments, then parses the arguments and returns a ParseResult with the options, positional parameters, and subcommands (if any) that were recognized and initialized during the parsing process.

public List<Object>
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 input
parseWithHandler
(CommandLine.IParseResultHandler2<R>
the function that will handle the result of successfully parsing the command line arguments
handler
,
String[]
the command line arguments
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Returns the result of calling parseWithHandlers(IParseResultHandler2, IExceptionHandler2, String...) with a new DefaultExceptionHandler in addition to the specified parse result handler and the specified command line arguments.
public List<Object>
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 input
parseWithHandlers
(CommandLine.IParseResultHandler2<R>
the function that will handle the result of successfully parsing the command line arguments
handler
,
CommandLine.IExceptionHandler2<R>
the function that can handle the ParameterException thrown when the command line arguments are invalid
exceptionHandler
,
String...
the command line arguments
args
)

Deprecated use execute(String...) and getExecutionResult() instead
Tries to parse the specified command line arguments, and if successful, delegates the processing of the resulting ParseResult object to the specified handler.
public static <
the type of the annotated object
T
>
T

Returns:

the specified annotated object
populateCommand
(T
the object to initialize. This object contains fields annotated with @Option or @Parameters.
command
,
String...
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 interface
populateSpec
(Class<T>
the interface that defines the command specification. This object contains getter methods annotated with @Option or @Parameters.
spec
,
String...
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
public static boolean

Returns:

true if help was printed, false otherwise
printHelpIfRequested
(CommandLine.ParseResult
contains the CommandLine objects found during parsing; check these to see if help was requested
parseResult
)

Delegates to executeHelpRequest(ParseResult).

public static boolean

Returns:

true if help was printed, false otherwise
printHelpIfRequested
(List<CommandLine>
the list of CommandLine objects to check if help was requested
parsedCommands
,
PrintStream
the PrintStream to print help to if requested
out
,
PrintStream
the error string to print diagnostic messages to, in addition to the output from the exception handler
err
,
CommandLine.Help.Ansi
for printing help messages using ANSI styles and colors
ansi
)

Deprecated use executeHelpRequest(ParseResult) instead
Delegates to the implementation of executeHelpRequest(ParseResult).
public static boolean

Returns:

true if help was printed, false otherwise
printHelpIfRequested
(List<CommandLine>
the list of CommandLine objects to check if help was requested
parsedCommands
,
PrintStream
the PrintStream to print help to if requested
out
,
PrintStream
the error string to print diagnostic messages to, in addition to the output from the exception handler
err
,
CommandLine.Help.ColorScheme
for printing help messages using ANSI styles and colors
colorScheme
)

Deprecated use executeHelpRequest(ParseResult) instead
Delegates to the implementation of executeHelpRequest(ParseResult).
public void
printVersionHelp(PrintStream
the printStream to print to
out
)

Delegates to printVersionHelp(PrintStream, Help.Ansi) with the ANSI setting of the configured color scheme.

public void
printVersionHelp(PrintStream
the printStream to print to
out
,
CommandLine.Help.Ansi
whether the usage message should include ANSI escape codes or not
ansi
)

Prints version information from the Command#version() annotation to the specified PrintStream.

public void
printVersionHelp(PrintStream
the printStream to print to
out
,
CommandLine.Help.Ansi
whether the usage message should include ANSI escape codes or not
ansi
,
Object...
Arguments referenced by the format specifiers in the version strings
params
)

Prints version information from the Command#version() annotation to the specified PrintStream.

public void
printVersionHelp(PrintWriter
the PrintWriter to print to
out
)

Delegates to printVersionHelp(PrintWriter, Help.Ansi, Object...) with the ANSI setting of the configured color scheme.

public void
printVersionHelp(PrintWriter
the PrintWriter to print to
out
,
CommandLine.Help.Ansi
whether the usage message should include ANSI escape codes or not
ansi
,
Object...
Arguments referenced by the format specifiers in the version strings
params
)

Prints version information from the Command#version() annotation to the specified PrintWriter.

public <
the target type
K
>
CommandLine

Returns:

this CommandLine object, to allow method chaining
registerConverter
(Class<K>
the target class to convert parameter string values to
cls
,
CommandLine.ITypeConverter<K>
the class capable of converting string values to the specified target type
converter
)

Registers the specified type converter for the specified class.

private static <T> Stack<T>
reverse(Stack<T> stack)

private static <T> T[]
reverseArray(T[] all)

private static <T> List<T>
reverseList(List<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 execute(String...) instead
Equivalent to 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 execute(String...) instead
Delegates to run(Runnable, PrintStream, PrintStream, Help.Ansi, String...) with System.err for diagnostic error messages and Help.Ansi#AUTO.
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.Help.Ansi
whether the usage message should include ANSI escape codes or not
ansi
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) instead
Delegates to run(Runnable, PrintStream, PrintStream, Help.Ansi, String...) 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.Help.Ansi
whether the usage message should include ANSI escape codes or not
ansi
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) instead
Convenience method to allow command line application authors to avoid some boilerplate code in their application.
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.IFactory
the factory responsible for instantiating the specified Runnable class and potentially injecting other components
factory
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) instead
Equivalent to 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.IFactory
the factory responsible for instantiating the specified Runnable class and potentially injecting other components
factory
,
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 execute(String...) instead
Delegates to run(Class, IFactory, PrintStream, PrintStream, Help.Ansi, String...) with System.err for diagnostic error messages, and Help.Ansi#AUTO.
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.IFactory
the factory responsible for instantiating the specified Runnable class and potentially injecting other components
factory
,
PrintStream
the printStream to print the usage help message to when the user requested help
out
,
CommandLine.Help.Ansi
whether the usage message should include ANSI escape codes or not
ansi
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) instead
Delegates to run(Class, IFactory, PrintStream, PrintStream, Help.Ansi, String...) 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.IFactory
the factory responsible for instantiating the specified Runnable class and potentially injecting other components
factory
,
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.Help.Ansi
whether the usage message should include ANSI escape codes or not
ansi
,
String...
the command line arguments to parse
args
)

Deprecated use execute(String...) instead
Convenience method to allow command line application authors to avoid some boilerplate code in their application.
public CommandLine

Returns:

this CommandLine object, to allow method chaining
setAbbreviatedOptionsAllowed
(boolean
the new setting
newValue
)

Sets whether abbreviated option names should be matched.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setAbbreviatedSubcommandsAllowed
(boolean
the 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:

this CommandLine object, to allow method chaining
setAllowOptionsAsOptionParameters
(boolean
the new setting. When 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 exception
newValue
)

Sets 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:

this CommandLine object, to allow method chaining
setAllowSubcommandsAsOptionParameters
(boolean
the new setting. When true, options can have parameter values that match subcommand names or aliases, when false, such values are rejected with a missing parameter exception
newValue
)

Sets 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:

this CommandLine object, to allow method chaining
setAtFileCommentChar
(Character
the character that starts a single-line comment or null. The default is '#'.
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).

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setCaseInsensitiveEnumValuesAllowed
(boolean
the new setting
newValue
)

Sets whether the parser should ignore case when converting arguments to enum values.

public CommandLine
setColorScheme(CommandLine.Help.ColorScheme
the new color scheme
colorScheme
)

Sets the color scheme to use when printing help.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setCommandName
(String
command 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:

this CommandLine object, to allow method chaining
setDefaultValueProvider
(CommandLine.IDefaultValueProvider
the default value provider to use
newValue
)

Sets a default value provider for the command and sub-commands

The specified setting will be registered with this CommandLine and the full hierarchy of its sub-commands and nested sub-subcommands at the moment this method is called.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setEndOfOptionsDelimiter
(String
the end-of-options delimiter; must not be null. The default is "--".
delimiter
)

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 chaining
setErr
(PrintWriter
the 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 chaining
setExecutionExceptionHandler
(CommandLine.IExecutionExceptionHandler
the handler for dealing with exceptions that occurred in the business logic when the execute method was invoked.
executionExceptionHandler
)

Sets a custom handler for dealing with exceptions that occurred in the Callable, Runnable or Method user object of a command when the command was executed via the execute method.

public void
setExecutionResult(Object
the business logic result, may be null
result
)

Sets the result of calling the business logic on the command's user object.

public CommandLine

Returns:

this CommandLine for method chaining
setExecutionStrategy
(CommandLine.IExecutionStrategy
the new execution strategy to run the user-specified command
executionStrategy
)

Sets the execution strategy that the execute method should use to invoke the business logic on the user objects of this command and/or the user-specified subcommand(s).

public CommandLine

Returns:

this CommandLine for method chaining
setExitCodeExceptionMapper
(CommandLine.IExitCodeExceptionMapper
the new value
exitCodeExceptionMapper
)

Sets the mapper used by the execute method to map exceptions to exit codes.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setExpandAtFiles
(boolean
whether "argument files" or @files should be expanded into their content
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.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setHelpFactory
(CommandLine.IHelpFactory
the new help factory. Must be non-null.
helpFactory
)

Sets a new IHelpFactory to customize the usage help message.

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.IHelpSectionRenderer> map)

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:

this CommandLine object, to allow method chaining
setNegatableOptionTransformer
(CommandLine.INegatableOptionTransformer
the INegatableOptionTransformer used to create negative option names.
transformer
)

Sets the INegatableOptionTransformer used to create the negative form of negatable options.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setOptionsCaseInsensitive
(boolean
the new setting
newValue
)

Sets whether upper case and lower case should be ignored when matching option names.

public CommandLine

Returns:

this CommandLine for method chaining
setOut
(PrintWriter
the 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:

this CommandLine object, to allow method chaining
setOverwrittenOptionsAllowed
(boolean
the new setting
newValue
)

Sets whether options for single-value fields can be specified multiple times on the command line without a OverwrittenOptionException being thrown.

public CommandLine

Returns:

this CommandLine for method chaining
setParameterExceptionHandler
(CommandLine.IParameterExceptionHandler
the new handler for dealing with invalid user input
parameterExceptionHandler
)

Sets the handler for dealing with invalid user input when the command is executed.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setPosixClusteredShortOptionsAllowed
(boolean
the new setting
newValue
)

Sets whether short options like -x -v -f SomeFile can be clustered together like -xvfSomeFile.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setResourceBundle
(ResourceBundle
the ResourceBundle containing usage help message strings
bundle
)

Sets the ResourceBundle containing usage help message strings.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setSeparator
(String
the 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:

this CommandLine object, to allow method chaining
setSplitQuotedStrings
(boolean
the new setting
newValue
)

Deprecated Most applications should not change the default.
Sets whether the parser is allowed to split quoted Strings.
public CommandLine

Returns:

this CommandLine object, to allow method chaining
setStopAtPositional
(boolean
true if all values following the first positional parameter should be treated as positional parameters, false otherwise
newValue
)

Sets 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:

this CommandLine object, to allow method chaining
setStopAtUnmatched
(boolean
true when an unmatched option should result in the remaining command line arguments to be added to the unmatchedArguments list
newValue
)

Sets whether the parser should stop interpreting options and positional parameters as soon as it encounters an unmatched option.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setSubcommandsCaseInsensitive
(boolean
the new setting
newValue
)

Sets whether upper case and lower case should be ignored when matching subcommands.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setToggleBooleanFlags
(boolean
the new setting
newValue
)

Sets whether the value of boolean flag options should be "toggled" when the option is matched.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setTrimQuotes
(boolean
the new setting
newValue
)

Sets whether the parser should trim quotes from command line arguments before processing them.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setUnmatchedArgumentsAllowed
(boolean
the new setting. When true, the last unmatched arguments are available via the getUnmatchedArguments() method.
newValue
)

Sets whether the end user may specify unmatched arguments on the command line without a UnmatchedArgumentException being thrown.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setUnmatchedOptionsAllowedAsOptionParameters
(boolean
the new setting. When true, options can have parameter values that resemble an option, when false, such values are rejected as unknown options
newValue
)

Sets whether options can have parameter values that resemble an option, or whether such values should be rejected as unknown options.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setUnmatchedOptionsArePositionalParams
(boolean
the new setting. When true, arguments on the command line that resemble an option should be treated as positional parameters.
newValue
)

Sets whether arguments on the command line that resemble an option should be treated as positional parameters.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setUsageHelpAutoWidth
(boolean
whether 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:

this CommandLine object, to allow method chaining
setUsageHelpLongOptionsMaxWidth
(int
the 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:

this CommandLine object, to allow method chaining
setUsageHelpWidth
(int
the maximum width of the usage help message
width
)

Sets the maximum width of the usage help message.

public CommandLine

Returns:

this CommandLine object, to allow method chaining
setUseSimplifiedAtFiles
(boolean
whether to use a simplified argument file format. The default is false.
simplifiedAtFiles
)

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
str(String[] arr, int i)

private static String

Returns:

converted and colored String
throwableToColorString
(Throwable
the Throwable to be converted
t
,
CommandLine.Help.ColorScheme
the ColorScheme to use
existingColorScheme
)

Convert a Throwable to a String , with message and stack traces extracted and colored according to ColorScheme.

private static CommandLine
public static CommandLine.Tracer

Returns:

the Tracer used internally for printing internal debug statements
tracer
()

Returns the Tracer used internally for printing internal debug statements.

private static String
unquote(String value)

public static void
usage(Object
the object annotated with Command, Option and Parameters
command
,
PrintStream
the print stream to print the help message to
out
)

Equivalent to new CommandLine(command).usage(out).

public static void
usage(Object
the object annotated with Command, Option and Parameters
command
,
PrintStream
the print stream to print the help message to
out
,
CommandLine.Help.Ansi
whether the usage message should contain ANSI escape codes or not
ansi
)

Equivalent to new CommandLine(command).usage(out, ansi).

public static void
usage(Object
the object annotated with Command, Option and Parameters
command
,
PrintStream
the print stream to print the help message to
out
,
CommandLine.Help.ColorScheme
the ColorScheme defining the styles for options, parameters and commands when ANSI is enabled
colorScheme
)

Equivalent to new CommandLine(command).usage(out, colorScheme).

public void
usage(PrintStream
the printStream to print to
out
)

Delegates to usage(PrintStream, Help.ColorScheme) with the configured color scheme.

public void
usage(PrintWriter
the PrintWriter to print to
writer
)

Delegates to usage(PrintWriter, Help.ColorScheme) with the configured color scheme.

public void
usage(PrintStream
the printStream to print to
out
,
CommandLine.Help.Ansi
whether the usage message should include ANSI escape codes or not
ansi
)

Delegates to usage(PrintStream, Help.ColorScheme) with the default color scheme.

public void
usage(PrintWriter writer, CommandLine.Help.Ansi ansi)

Similar to usage(PrintStream, Help.Ansi) but with the specified PrintWriter instead of a PrintStream.

public void
usage(PrintStream
the PrintStream to print the usage help message to
out
,
CommandLine.Help.ColorScheme
the ColorScheme defining the styles for options, parameters and commands when ANSI is enabled
colorScheme
)

Prints a usage help message for the annotated command class to the specified PrintStream.

public void
usage(PrintWriter writer, CommandLine.Help.ColorScheme colorScheme)

Similar to usage(PrintStream, Help.ColorScheme), but with the specified PrintWriter instead of a PrintStream.

private StringBuilder
private static void
pack-priv static String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait