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 booleanprivate intprivate booleanprivate static final StringValue displayed in trace logs for options with echo=false.private CommandLine.ParseResult.Builderprivate int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate voidaddPostponedRequiredArgs(Collection<CommandLine.Model.ArgSpec> inheritedRequired, List<CommandLine.Model.ArgSpec> required) private voidaddToInitialized(CommandLine.Model.ArgSpec argSpec, Set<CommandLine.Model.ArgSpec> initialized) private intaddUserInputToList(CommandLine.Model.ArgSpec argSpec, List<Object> result, int consumed, String argDescription) private booleanapplyDefault(CommandLine.IDefaultValueProvider defaultValueProvider, CommandLine.Model.ArgSpec arg) private voidapplyDefaultValues(List<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized) private voidapplyGroupDefaults(CommandLine.IDefaultValueProvider defaultValueProvider, CommandLine.Model.ArgGroupSpec group, List<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized) private intapplyOption(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 intapplyValuesToArrayField(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 intapplyValuesToCollectionField(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 intapplyValuesToMapField(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Set<CommandLine.Model.ArgSpec> initialized, String argDescription) private intapplyValueToSingleValuedField(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 booleanassertNoMissingMandatoryParameter(CommandLine.Model.ArgSpec argSpec, Stack<String> args, int i, CommandLine.Range arity) private booleanassertNoMissingParameters(CommandLine.Model.ArgSpec argSpec, CommandLine.Range arity, Stack<String> args) private booleanbooleanValue(CommandLine.Model.ArgSpec argSpec, Object value) private booleancanConsumeOneArgument(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg, String argDescription) private booleancanConsumeOneMapArgument(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 voidclear()private voidprivate voidclear(CommandLine.Model.ArgSpec argSpec) private CommandLine.Model.ParserSpecconfig()consumeArguments(CommandLine.Model.ArgSpec argSpec, boolean negated, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, boolean unquoted, CommandLine.Range arity, Stack<String> args, String argDescription) private intconsumedCount(int i, int initialSize, CommandLine.Model.ArgSpec arg) private intconsumedCountMap(int i, int initialSize, CommandLine.Model.ArgSpec arg) private voidconsumeMapArguments(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, Stack<String> args, Map<Object, Object> result, String argDescription) private intconsumeOneArgument(CommandLine.Model.ArgSpec argSpec, CommandLine.LookBehind lookBehind, boolean alreadyUnquoted, CommandLine.Range arity, int consumed, String arg, List<Object> result, int index, String argDescription) private voidconsumeOneMapArgument(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 StringcreateMissingParameterMessageFoundOtherOption(CommandLine.Model.ArgSpec argSpec, Stack<String> args, int i, CommandLine.Range arity) private StringcreateUserInputDebugString(CommandLine.Model.ArgSpec argSpec, char[] result, String name) private booleanprivate voidprivate voidprivate CommandLine.ITypeConverter<?> getActualTypeConverter(Class<?> type, CommandLine.Model.ArgSpec argSpec) private CommandLine.ITypeConverter<Object> getEnumTypeConverter(Class<?> type) private StringgetMaskedValue(CommandLine.Model.ArgSpec argSpec, String input) (package private) intprivate CommandLine.ITypeConverter<?> getTypeConverter(Class<?>[] types, CommandLine.Model.ArgSpec argSpec, int index) private voidhandleUnmatchedArgument(Stack<String> args) private booleanis(CommandLine.Model.ArgSpec p, String attribute, boolean value) private booleanprivate booleanisArgResemblesOptionThereforeDiscontinue(CommandLine.Model.ArgSpec argSpec, Stack<String> args, int i, CommandLine.Range arity) private booleanprivate booleanprivate booleanReturns true if the specified arg is "--", a registered option, or potentially a clustered POSIX option.private booleanisStandaloneOption(String arg) (package private) void(package private) List<CommandLine> Entry point into parsing command line arguments.private voidparse(List<CommandLine> parsedCommands, Stack<String> argumentStack, String[] originalArgs, List<Object> nowProcessing, Collection<CommandLine.Model.ArgSpec> inheritedRequired) private voidparse(List<CommandLine> parsedCommands, Stack<String> argumentStack, String[] originalArgs, List<Object> nowProcessing, Collection<CommandLine.Model.ArgSpec> inheritedRequired, Set<CommandLine.Model.ArgSpec> initialized) (package private) Stringprivate voidprocessArguments(List<CommandLine> parsedCommands, Stack<String> args, Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, String[] originalArgs, List<Object> nowProcessing) private voidprocessClusteredShortOptions(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, String arg, boolean alreadyUnquoted, Stack<String> args) private voidprocessPositionalParameter(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, boolean alreadyUnquoted, Stack<String> args) private voidprocessRemainderAsPositionalParameters(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, Stack<String> args) private voidprocessStandaloneOption(Collection<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> initialized, String arg, boolean alreadyUnquoted, Stack<String> args, CommandLine.LookBehind lookBehind) private voidprocessSubcommand(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 voidprivate voidreg(Class<?> timeClass, CommandLine.BuiltIn.ISO8601TimeConverter converter) private voidprivate String[]splitKeyValue(CommandLine.Model.ArgSpec argSpec, String value) private ObjecttryConvert(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 voidprivate voidprivate voidvalidateConstraints(Stack<String> argumentStack, List<CommandLine.Model.ArgSpec> required, Set<CommandLine.Model.ArgSpec> matched) private booleanvarargCanConsumeNextValue(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
-