Package aQute.lib.getopt
Class CommandLine
java.lang.Object
aQute.lib.getopt.CommandLine
Helps parsing command lines. This class takes target object, a primary
command, and a list of arguments. It will then find the command in the target
object. The method of this command must start with a "_" and take an
parameter of Options type. Usually this is an interface that extends Options.
The methods on this interface are options or flags (when they return
boolean).
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Assign an option, must handle flags, parameters, and parameters that can happen multiple times.Execute a command in a target object with a set of options and arguments and returns help text if something fails.void
generateDocumentation
(Object target, Appendable out) getCommands
(Object target) Parse a class and return a list of command namesprivate CommandLine.Option
getOptions
(Class<? extends Options> interf) Answer a list of the options specified in an options interface<T extends Options>
TgetOptions
(Class<T> specification, List<String> arguments) Parse the options in a command line and return an interface that provides the options from this command line.private String
private String
getTypeDescriptor
(Type type) Show a type in a nice wayprivate String
private void
void
Show all commands in a targetvoid
Show the full help for a given commandvoid
Provide a help text.private boolean
Answer if the method is marked mandatoryprivate boolean
private static String
-
Field Details
-
Constructor Details
-
CommandLine
-
-
Method Details
-
execute
Execute a command in a target object with a set of options and arguments and returns help text if something fails. Errors are reported.- Throws:
Exception
-
generateDocumentation
-
help
- Throws:
Exception
-
getOptions
public <T extends Options> T getOptions(Class<T> specification, List<String> arguments) throws Exception Parse the options in a command line and return an interface that provides the options from this command line. This will parse up to (and including) -- or an argument that does not start with -- Throws:
Exception
-
getOptions
Answer a list of the options specified in an options interface -
assignOptionValue
public void assignOptionValue(Map<String, Object> options, Method m, List<String> args, boolean last) Assign an option, must handle flags, parameters, and parameters that can happen multiple times.- Parameters:
options
- The command line mapargs
- the args inputm
- the selected method for this optionlast
- if this is the last in a multi single character option
-
help
Provide a help text. -
help
-
getOption
-
getSynopsis
-
lastPart
-
help
Show all commands in a target- Throws:
Exception
-
help
Show the full help for a given command -
getCommands
Parse a class and return a list of command names- Parameters:
target
-- Returns:
- command names
-
isMandatory
Answer if the method is marked mandatory -
isOption
- Parameters:
m
-
-
getTypeDescriptor
Show a type in a nice way -
getResult
-
subCmd
- Throws:
Exception
-