Package aQute.lib.getopt
Class CommandLine
- java.lang.Object
-
- aQute.lib.getopt.CommandLine
-
public class CommandLine extends java.lang.ObjectHelps 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).
-
-
Constructor Summary
Constructors Constructor Description CommandLine(Reporter reporter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassignOptionValue(java.util.Map<java.lang.String,java.lang.Object> options, java.lang.reflect.Method m, java.util.List<java.lang.String> args, boolean last)Assign an option, must handle flags, parameters, and parameters that can happen multiple times.java.lang.Stringexecute(java.lang.Object target, java.lang.String cmd, java.util.List<java.lang.String> input)Execute a command in a target object with a set of options and arguments and returns help text if something fails.voidgenerateDocumentation(java.lang.Object target, java.lang.Appendable out)java.util.Map<java.lang.String,java.lang.reflect.Method>getCommands(java.lang.Object target)Parse a class and return a list of command names<T extends Options>
TgetOptions(java.lang.Class<T> specification, java.util.List<java.lang.String> arguments)Parse the options in a command line and return an interface that provides the options from this command line.java.lang.ObjectgetResult()voidhelp(java.util.Formatter f, java.lang.Object target)Show all commands in a targetvoidhelp(java.util.Formatter f, java.lang.Object target, java.lang.String cmd)Show the full help for a given commandvoidhelp(java.util.Formatter f, java.lang.Object target, java.lang.String cmd, java.lang.Class<? extends Options> specification)Provide a help text.java.lang.StringsubCmd(Options opts, java.lang.Object target)
-
-
-
Constructor Detail
-
CommandLine
public CommandLine(Reporter reporter)
-
-
Method Detail
-
execute
public java.lang.String execute(java.lang.Object target, java.lang.String cmd, java.util.List<java.lang.String> input) throws java.lang.ExceptionExecute a command in a target object with a set of options and arguments and returns help text if something fails. Errors are reported.- Throws:
java.lang.Exception
-
generateDocumentation
public void generateDocumentation(java.lang.Object target, java.lang.Appendable out)
-
getOptions
public <T extends Options> T getOptions(java.lang.Class<T> specification, java.util.List<java.lang.String> arguments) throws java.lang.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:
java.lang.Exception
-
assignOptionValue
public void assignOptionValue(java.util.Map<java.lang.String,java.lang.Object> options, java.lang.reflect.Method m, java.util.List<java.lang.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
public void help(java.util.Formatter f, java.lang.Object target, java.lang.String cmd, java.lang.Class<? extends Options> specification)Provide a help text.
-
help
public void help(java.util.Formatter f, java.lang.Object target) throws java.lang.ExceptionShow all commands in a target- Throws:
java.lang.Exception
-
help
public void help(java.util.Formatter f, java.lang.Object target, java.lang.String cmd)Show the full help for a given command
-
getCommands
public java.util.Map<java.lang.String,java.lang.reflect.Method> getCommands(java.lang.Object target)
Parse a class and return a list of command names- Parameters:
target-- Returns:
- command names
-
getResult
public java.lang.Object getResult()
-
subCmd
public java.lang.String subCmd(Options opts, java.lang.Object target) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-