Package picocli
Class CommandLine.Interpreter
java.lang.Object
picocli.CommandLine.Interpreter
- Enclosing class:
CommandLine
Helper class responsible for processing command line arguments.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map
<Class<?>, CommandLine.ITypeConverter<?>> private boolean
private int
private boolean
private static final String
Value displayed in trace logs for options with echo=false.private CommandLine.ParseResult.Builder
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private void
addPostponedRequiredArgs
(Collection<CommandLine.Model.ArgSpec> inheritedRequired, List<CommandLine.Model.ArgSpec> required) private void
addToInitialized
(CommandLine.Model.ArgSpec argSpec, Set<CommandLine.Model.ArgSpec> initialized) private int
addUserInputToList
(CommandLine.Model.ArgSpec argSpec, List<Object> result, int consumed, String argDescription) private boolean
applyDefault
(CommandLine.IDefaultValueProvider defaultValueProvider, CommandLine.Model.ArgSpec arg) private void
applyDefaultValues
(List<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized) private void
applyGroupDefaults
(CommandLine.IDefaultValueProvider defaultValueProvider, CommandLine.Model.ArgGroupSpec group, List<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized) private int
applyOption
(CommandLine.Model.ArgSpec argSpec, boolean negated, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Set<CommandLine.Model.ArgSpec> initialized, String argDescription) private int
applyValuesToArrayField
(CommandLine.Model.ArgSpec argSpec, boolean negated, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Set<CommandLine.Model.ArgSpec> initialized, String argDescription) private int
applyValuesToCollectionField
(CommandLine.Model.ArgSpec argSpec, boolean negated, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Set<CommandLine.Model.ArgSpec> initialized, String argDescription) private int
applyValuesToMapField
(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Set<CommandLine.Model.ArgSpec> initialized, String argDescription) private int
applyValueToSingleValuedField
(CommandLine.Model.ArgSpec argSpec, boolean negated, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range derivedArity, Stack<String> args, Set<CommandLine.Model.ArgSpec> initialized, String argDescription) private boolean
assertNoMissingMandatoryParameter
(CommandLine.Model.ArgSpec argSpec, Stack<String> args, int i, CommandLine.Range arity) private boolean
assertNoMissingParameters
(CommandLine.Model.ArgSpec argSpec, CommandLine.Range arity, Stack<String> args) private boolean
booleanValue
(CommandLine.Model.ArgSpec argSpec, Object value) private boolean
canConsumeOneArgument
(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg, String argDescription) private boolean
canConsumeOneMapArgument
(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg, Class<?>[] classes, CommandLine.ITypeConverter<?> keyConverter, CommandLine.ITypeConverter<?> valueConverter, String argDescription) private void
clear()
private void
private void
clear
(CommandLine.Model.ArgSpec argSpec) private CommandLine.Model.ParserSpec
config()
consumeArguments
(CommandLine.Model.ArgSpec argSpec, boolean negated, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, boolean unquoted, CommandLine.Range arity, Stack<String> args, String argDescription) private int
consumedCount
(int i, int initialSize, CommandLine.Model.ArgSpec arg) private int
consumedCountMap
(int i, int initialSize, CommandLine.Model.ArgSpec arg) private void
consumeMapArguments
(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Map<Object, Object> result, String argDescription) private int
consumeOneArgument
(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg, List<Object> result, int index, String argDescription) private void
consumeOneMapArgument
(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg, Class<?>[] classes, CommandLine.ITypeConverter<?> keyConverter, CommandLine.ITypeConverter<?> valueConverter, Map<Object, Object> result, int index, String argDescription) private Collection
<Object> createCollection
(Class<?> collectionClass, Class<?>[] elementType) private String
createMissingParameterMessageFoundOtherOption
(CommandLine.Model.ArgSpec argSpec, Stack<String> args, int i, CommandLine.Range arity) private String
createUserInputDebugString
(CommandLine.Model.ArgSpec argSpec, char[] result, String name) private boolean
private void
private void
private CommandLine.ITypeConverter
<?> getActualTypeConverter
(Class<?> type, CommandLine.Model.ArgSpec argSpec) private CommandLine.ITypeConverter
<Object> getEnumTypeConverter
(Class<?> type) private String
getMaskedValue
(CommandLine.Model.ArgSpec argSpec, String input) (package private) int
private CommandLine.ITypeConverter
<?> getTypeConverter
(Class<?>[] types, CommandLine.Model.ArgSpec argSpec, int index) private void
handleUnmatchedArgument
(Stack<String> args) private boolean
is
(CommandLine.Model.ArgSpec p, String attribute, boolean value) private boolean
private boolean
isArgResemblesOptionThereforeDiscontinue
(CommandLine.Model.ArgSpec argSpec, Stack<String> args, int i, CommandLine.Range arity) private boolean
private boolean
private boolean
Returns true if the specified arg is "--", a registered option, or potentially a clustered POSIX option.private boolean
isStandaloneOption
(String arg) (package private) void
(package private) List
<CommandLine> Entry point into parsing command line arguments.private void
parse
(List<CommandLine> parsedCommands, Stack<String> argumentStack, String[] originalArgs, List<Object> nowProcessing, Collection<CommandLine.Model.ArgSpec> inheritedRequired) private void
parse
(List<CommandLine> parsedCommands, Stack<String> argumentStack, String[] originalArgs, List<Object> nowProcessing, Collection<CommandLine.Model.ArgSpec> inheritedRequired, Set<CommandLine.Model.ArgSpec> initialized) (package private) String
private void
processArguments
(List<CommandLine> parsedCommands, Stack<String> args, Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, String[] originalArgs, List<Object> nowProcessing) private void
processClusteredShortOptions
(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, String arg, boolean alreadyUnquoted, Stack<String> args) private void
processPositionalParameter
(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, boolean alreadyUnquoted, Stack<String> args) private void
processRemainderAsPositionalParameters
(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, Stack<String> args) private void
processStandaloneOption
(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, String arg, boolean alreadyUnquoted, Stack<String> args, CommandLine.LookBehind lookBehind) private void
processSubcommand
(CommandLine subcommand, CommandLine.ParseResult.Builder builder, List<CommandLine> parsedCommands, Stack<String> args, Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, String[] originalArgs, List<Object> nowProcessing, String separator, String arg) (package private) char[]
readPassword
(String prompt) (package private) char[]
readUserInput
(CommandLine.Model.ArgSpec argSpec) (package private) char[]
readUserInputWithEchoing
(String prompt) private void
private void
reg
(Class<?> timeClass, CommandLine.BuiltIn.ISO8601TimeConverter converter) private void
private String[]
splitKeyValue
(CommandLine.Model.ArgSpec argSpec, String value) private Object
tryConvert
(CommandLine.Model.ArgSpec argSpec, int index, CommandLine.ITypeConverter<?> converter, String value, int typeIndex) private String[]
unquoteAndSplit
(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg) private void
private void
private void
validateConstraints
(Stack<String> argumentStack, List<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> matched) private boolean
varargCanConsumeNextValue
(CommandLine.Model.ArgSpec argSpec, String nextValue) Returns whether the next argument can be assigned to a vararg option/positional parameter.
-
Field Details
-
MASKED_VALUE
Value displayed in trace logs for options with echo=false.- See Also:
-
converterRegistry
-
isHelpRequested
private boolean isHelpRequested -
position
private int position -
interactiveCount
private int interactiveCount -
endOfOptions
private boolean endOfOptions -
parseResultBuilder
-
-
Constructor Details
-
Interpreter
Interpreter()
-
-
Method Details
-
registerBuiltInConverters
private void registerBuiltInConverters() -
excl
-
reg
-
reg
-
config
-
parse
Entry point into parsing command line arguments.- Parameters:
args
- the command line arguments- Returns:
- a list with all commands and subcommands initialized by this method
- Throws:
CommandLine.ParameterException
- if the specified command line arguments are invalid
-
addOrExpand
-
expandArgumentFile
-
expandValidArgumentFile
-
clear
private void clear() -
clear
-
clear
-
maybeThrow
- Throws:
CommandLine.PicocliException
-
parse
private void parse(List<CommandLine> parsedCommands, Stack<String> argumentStack, String[] originalArgs, List<Object> nowProcessing, Collection<CommandLine.Model.ArgSpec> inheritedRequired) -
parse
private void parse(List<CommandLine> parsedCommands, Stack<String> argumentStack, String[] originalArgs, List<Object> nowProcessing, Collection<CommandLine.Model.ArgSpec> inheritedRequired, Set<CommandLine.Model.ArgSpec> initialized) -
addPostponedRequiredArgs
private void addPostponedRequiredArgs(Collection<CommandLine.Model.ArgSpec> inheritedRequired, List<CommandLine.Model.ArgSpec> required) -
validateConstraints
private void validateConstraints(Stack<String> argumentStack, List<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> matched) -
applyDefaultValues
private void applyDefaultValues(List<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized) throws Exception - Throws:
Exception
-
applyGroupDefaults
private void applyGroupDefaults(CommandLine.IDefaultValueProvider defaultValueProvider, CommandLine.Model.ArgGroupSpec group, List<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized) throws Exception - Throws:
Exception
-
applyDefault
private boolean applyDefault(CommandLine.IDefaultValueProvider defaultValueProvider, CommandLine.Model.ArgSpec arg) throws Exception - Throws:
Exception
-
stack
-
processArguments
private void processArguments(List<CommandLine> parsedCommands, Stack<String> args, Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, String[] originalArgs, List<Object> nowProcessing) throws Exception - Throws:
Exception
-
processSubcommand
private void processSubcommand(CommandLine subcommand, CommandLine.ParseResult.Builder builder, List<CommandLine> parsedCommands, Stack<String> args, Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, String[] originalArgs, List<Object> nowProcessing, String separator, String arg) -
isStandaloneOption
-
handleUnmatchedArgument
- Throws:
Exception
-
processRemainderAsPositionalParameters
private void processRemainderAsPositionalParameters(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, Stack<String> args) throws Exception - Throws:
Exception
-
processPositionalParameter
private void processPositionalParameter(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, boolean alreadyUnquoted, Stack<String> args) throws Exception - Throws:
Exception
-
processStandaloneOption
private void processStandaloneOption(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, String arg, boolean alreadyUnquoted, Stack<String> args, CommandLine.LookBehind lookBehind) throws Exception - Throws:
Exception
-
processClusteredShortOptions
private void processClusteredShortOptions(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, String arg, boolean alreadyUnquoted, Stack<String> args) throws Exception - Throws:
Exception
-
applyOption
private int applyOption(CommandLine.Model.ArgSpec argSpec, boolean negated, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Set<CommandLine.Model.ArgSpec> initialized, String argDescription) throws Exception - Throws:
Exception
-
addToInitialized
private void addToInitialized(CommandLine.Model.ArgSpec argSpec, Set<CommandLine.Model.ArgSpec> initialized) -
applyValueToSingleValuedField
private int applyValueToSingleValuedField(CommandLine.Model.ArgSpec argSpec, boolean negated, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range derivedArity, Stack<String> args, Set<CommandLine.Model.ArgSpec> initialized, String argDescription) throws Exception - Throws:
Exception
-
applyValuesToMapField
private int applyValuesToMapField(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Set<CommandLine.Model.ArgSpec> initialized, String argDescription) throws Exception - Throws:
Exception
-
consumeMapArguments
private void consumeMapArguments(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Map<Object, Object> result, String argDescription) throws Exception- Throws:
Exception
-
consumeOneMapArgument
private void consumeOneMapArgument(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg, Class<?>[] classes, CommandLine.ITypeConverter<?> keyConverter, CommandLine.ITypeConverter<?> valueConverter, Map<Object, Object> result, int index, String argDescription) throws Exception- Throws:
Exception
-
unquoteAndSplit
private String[] unquoteAndSplit(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg) -
canConsumeOneMapArgument
private boolean canConsumeOneMapArgument(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg, Class<?>[] classes, CommandLine.ITypeConverter<?> keyConverter, CommandLine.ITypeConverter<?> valueConverter, String argDescription) -
splitKeyValue
-
assertNoMissingMandatoryParameter
private boolean assertNoMissingMandatoryParameter(CommandLine.Model.ArgSpec argSpec, Stack<String> args, int i, CommandLine.Range arity) -
createMissingParameterMessageFoundOtherOption
private String createMissingParameterMessageFoundOtherOption(CommandLine.Model.ArgSpec argSpec, Stack<String> args, int i, CommandLine.Range arity) -
isArgResemblesOptionThereforeDiscontinue
private boolean isArgResemblesOptionThereforeDiscontinue(CommandLine.Model.ArgSpec argSpec, Stack<String> args, int i, CommandLine.Range arity) throws Exception - Throws:
Exception
-
applyValuesToArrayField
private int applyValuesToArrayField(CommandLine.Model.ArgSpec argSpec, boolean negated, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Set<CommandLine.Model.ArgSpec> initialized, String argDescription) throws Exception - Throws:
Exception
-
applyValuesToCollectionField
private int applyValuesToCollectionField(CommandLine.Model.ArgSpec argSpec, boolean negated, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Set<CommandLine.Model.ArgSpec> initialized, String argDescription) throws Exception - Throws:
Exception
-
consumeArguments
private List<Object> consumeArguments(CommandLine.Model.ArgSpec argSpec, boolean negated, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, boolean unquoted, CommandLine.Range arity, Stack<String> args, String argDescription) throws Exception - Throws:
Exception
-
consumedCount
-
consumedCountMap
-
addUserInputToList
private int addUserInputToList(CommandLine.Model.ArgSpec argSpec, List<Object> result, int consumed, String argDescription) -
getMaskedValue
-
consumeOneArgument
private int consumeOneArgument(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg, List<Object> result, int index, String argDescription) -
canConsumeOneArgument
private boolean canConsumeOneArgument(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg, String argDescription) -
varargCanConsumeNextValue
Returns whether the next argument can be assigned to a vararg option/positional parameter.Usually, we stop if we encounter '--', a command, or another option. However, if end-of-options has been reached, positional parameters may consume all remaining arguments.
-
isOption
Returns true if the specified arg is "--", a registered option, or potentially a clustered POSIX option. Called when parsing varargs parameters for a multi-value option. When an option is encountered, the remainder should not be interpreted as vararg elements.- Parameters:
arg
- the string to determine whether it is an option or not- Returns:
- true if it is an option, false otherwise
- See Also:
-
isCommand
-
isEndOfOptionsDelimiter
-
tryConvert
private Object tryConvert(CommandLine.Model.ArgSpec argSpec, int index, CommandLine.ITypeConverter<?> converter, String value, int typeIndex) throws CommandLine.ParameterException - Throws:
CommandLine.ParameterException
-
isAnyHelpRequested
private boolean isAnyHelpRequested() -
updateHelpRequested
-
updateHelpRequested
-
is
-
createCollection
private Collection<Object> createCollection(Class<?> collectionClass, Class<?>[] elementType) throws Exception - Throws:
Exception
-
createMap
- Throws:
Exception
-
getTypeConverter
private CommandLine.ITypeConverter<?> getTypeConverter(Class<?>[] types, CommandLine.Model.ArgSpec argSpec, int index) -
getActualTypeConverter
private CommandLine.ITypeConverter<?> getActualTypeConverter(Class<?> type, CommandLine.Model.ArgSpec argSpec) -
getEnumTypeConverter
-
booleanValue
-
assertNoMissingParameters
private boolean assertNoMissingParameters(CommandLine.Model.ArgSpec argSpec, CommandLine.Range arity, Stack<String> args) -
readUserInput
-
createUserInputDebugString
private String createUserInputDebugString(CommandLine.Model.ArgSpec argSpec, char[] result, String name) -
readPassword
-
readUserInputWithEchoing
-
getPosition
-
positionDesc
-