Class CommandLine.Interpreter
java.lang.Object
org.apache.logging.log4j.core.tools.picocli.CommandLine.Interpreter
- Enclosing class:
- CommandLine
Helper class responsible for processing command line arguments.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Object
private final Map<String,
CommandLine> private final Map<Class<?>,
CommandLine.ITypeConverter<?>> private boolean
private int
private String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate int
applyOption
(Field field, Class<?> annotation, CommandLine.Range arity, boolean valueAttachedToOption, Stack<String> args, Set<Field> initialized, String argDescription) private int
applyValuesToArrayField
(Field field, Class<?> annotation, CommandLine.Range arity, Stack<String> args, Class<?> cls, String argDescription) private int
applyValuesToCollectionField
(Field field, Class<?> annotation, CommandLine.Range arity, Stack<String> args, Class<?> cls, String argDescription) private int
applyValuesToMapField
(Field field, Class<?> annotation, CommandLine.Range arity, Stack<String> args, Class<?> cls, String argDescription) private int
applyValueToSingleValuedField
(Field field, CommandLine.Range arity, Stack<String> args, Class<?> cls, Set<Field> initialized, String argDescription) private void
assertNoMissingParameters
(Field field, int arity, Stack<String> args) private void
checkMaxArityExceeded
(CommandLine.Range arity, int remainder, Field field, String[] values) consumeArguments
(Field field, Class<?> annotation, CommandLine.Range arity, Stack<String> args, Class<?> type, int originalSize, String argDescription) private void
consumeMapArguments
(Field field, CommandLine.Range arity, Stack<String> args, Class<?>[] classes, CommandLine.ITypeConverter<?> keyConverter, CommandLine.ITypeConverter<?> valueConverter, Map<Object, Object> result, String argDescription) private int
consumeOneArgument
(Field field, CommandLine.Range arity, Stack<String> args, Class<?> type, List<Object> result, int index, int originalSize, String argDescription) private void
consumeOneMapArgument
(Field field, CommandLine.Range arity, Stack<String> args, Class<?>[] classes, CommandLine.ITypeConverter<?> keyConverter, CommandLine.ITypeConverter<?> valueConverter, Map<Object, Object> result, int index, String argDescription) private Collection<Object>
createCollection
(Class<?> collectionClass) private CommandLine.ITypeConverter<?>
getTypeConverter
(Class<?> type, Field field) private void
private void
handleUnmatchedArguments
(Stack<String> args) private boolean
private boolean
private boolean
Called when parsing varargs parameters for a multi-value option.private String
optionDescription
(String prefix, Field field, int index) (package private) List<CommandLine>
Entry point into parsing command line arguments.private void
private void
processArguments
(List<CommandLine> parsedCommands, Stack<String> args, Collection<Field> required, Set<Field> initialized, String[] originalArgs) private void
processClusteredShortOptions
(Collection<Field> required, Set<Field> initialized, String arg, Stack<String> args) private void
processPositionalParameter
(Collection<Field> required, Set<Field> initialized, Stack<String> args) private void
processRemainderAsPositionalParameters
(Collection<Field> required, Set<Field> initialized, Stack<String> args) private void
processStandaloneOption
(Collection<Field> required, Set<Field> initialized, String arg, Stack<String> args, boolean paramAttachedToKey) private boolean
resemblesOption
(String arg) private String[]
private String
splitRegex
(Field field) private String
private Object
tryConvert
(Field field, int index, CommandLine.ITypeConverter<?> converter, String value, Class<?> type) private String
private void
updateHelpRequested
(Field field)
-
Field Details
-
commands
-
converterRegistry
-
optionName2Field
-
singleCharOption2Field
-
requiredFields
-
positionalParametersFields
-
command
-
isHelpRequested
private boolean isHelpRequested -
separator
-
position
private int position
-
-
Constructor Details
-
Interpreter
Interpreter(Object command)
-
-
Method Details
-
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
-
parse
private void parse(List<CommandLine> parsedCommands, Stack<String> argumentStack, String[] originalArgs) -
processArguments
private void processArguments(List<CommandLine> parsedCommands, Stack<String> args, Collection<Field> required, Set<Field> initialized, String[] originalArgs) throws Exception - Throws:
Exception
-
resemblesOption
-
handleUnmatchedArguments
-
handleUnmatchedArguments
-
processRemainderAsPositionalParameters
private void processRemainderAsPositionalParameters(Collection<Field> required, Set<Field> initialized, Stack<String> args) throws Exception - Throws:
Exception
-
processPositionalParameter
private void processPositionalParameter(Collection<Field> required, Set<Field> initialized, Stack<String> args) throws Exception - Throws:
Exception
-
processStandaloneOption
private void processStandaloneOption(Collection<Field> required, Set<Field> initialized, String arg, Stack<String> args, boolean paramAttachedToKey) throws Exception - Throws:
Exception
-
processClusteredShortOptions
private void processClusteredShortOptions(Collection<Field> required, Set<Field> initialized, String arg, Stack<String> args) throws Exception - Throws:
Exception
-
applyOption
private int applyOption(Field field, Class<?> annotation, CommandLine.Range arity, boolean valueAttachedToOption, Stack<String> args, Set<Field> initialized, String argDescription) throws Exception - Throws:
Exception
-
applyValueToSingleValuedField
private int applyValueToSingleValuedField(Field field, CommandLine.Range arity, Stack<String> args, Class<?> cls, Set<Field> initialized, String argDescription) throws Exception - Throws:
Exception
-
applyValuesToMapField
private int applyValuesToMapField(Field field, Class<?> annotation, CommandLine.Range arity, Stack<String> args, Class<?> cls, String argDescription) throws Exception - Throws:
Exception
-
consumeMapArguments
private void consumeMapArguments(Field field, CommandLine.Range arity, Stack<String> args, Class<?>[] classes, CommandLine.ITypeConverter<?> keyConverter, CommandLine.ITypeConverter<?> valueConverter, Map<Object, Object> result, String argDescription) throws Exception- Throws:
Exception
-
consumeOneMapArgument
private void consumeOneMapArgument(Field field, CommandLine.Range arity, Stack<String> args, Class<?>[] classes, CommandLine.ITypeConverter<?> keyConverter, CommandLine.ITypeConverter<?> valueConverter, Map<Object, Object> result, int index, String argDescription) throws Exception- Throws:
Exception
-
checkMaxArityExceeded
private void checkMaxArityExceeded(CommandLine.Range arity, int remainder, Field field, String[] values) -
applyValuesToArrayField
private int applyValuesToArrayField(Field field, Class<?> annotation, CommandLine.Range arity, Stack<String> args, Class<?> cls, String argDescription) throws Exception - Throws:
Exception
-
applyValuesToCollectionField
private int applyValuesToCollectionField(Field field, Class<?> annotation, CommandLine.Range arity, Stack<String> args, Class<?> cls, String argDescription) throws Exception - Throws:
Exception
-
consumeArguments
private List<Object> consumeArguments(Field field, Class<?> annotation, CommandLine.Range arity, Stack<String> args, Class<?> type, int originalSize, String argDescription) throws Exception - Throws:
Exception
-
consumeOneArgument
private int consumeOneArgument(Field field, CommandLine.Range arity, Stack<String> args, Class<?> type, List<Object> result, int index, int originalSize, String argDescription) throws Exception - Throws:
Exception
-
splitRegex
-
split
-
isOption
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
-
tryConvert
private Object tryConvert(Field field, int index, CommandLine.ITypeConverter<?> converter, String value, Class<?> type) throws Exception - Throws:
Exception
-
optionDescription
-
isAnyHelpRequested
private boolean isAnyHelpRequested() -
updateHelpRequested
-
is
-
createCollection
- Throws:
Exception
-
createMap
- Throws:
Exception
-
getTypeConverter
-
assertNoMissingParameters
-
trim
-
unquote
-