aQute.lib.getopt
Class CommandLine

java.lang.Object
  extended by aQute.lib.getopt.CommandLine

public class CommandLine
extends Object

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).


Constructor Summary
CommandLine(Reporter reporter)
           
 
Method Summary
 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.
 String execute(Object target, String cmd, List<String> input)
          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)
           
 Map<String,Method> getCommands(Object target)
          Parse a class and return a list of command names
<T extends Options>
T
getOptions(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.
 Object getResult()
           
 void help(Formatter f, Object target)
          Show all commands in a target
 void help(Formatter f, Object target, String cmd)
          Show the full help for a given command
 void help(Formatter f, Object target, String cmd, Class<? extends Options> specification)
          Provide a help text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLine

public CommandLine(Reporter reporter)
Method Detail

execute

public String execute(Object target,
                      String cmd,
                      List<String> input)
               throws Exception
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

public void generateDocumentation(Object target,
                                  Appendable out)

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

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 map
args - the args input
i - where we are
m - the selected method for this option
last - if this is the last in a multi single character option

help

public void help(Formatter f,
                 Object target,
                 String cmd,
                 Class<? extends Options> specification)
Provide a help text.


help

public void help(Formatter f,
                 Object target)
          throws Exception
Show all commands in a target

Throws:
Exception

help

public void help(Formatter f,
                 Object target,
                 String cmd)
Show the full help for a given command


getCommands

public Map<String,Method> getCommands(Object target)
Parse a class and return a list of command names

Parameters:
target -
Returns:

getResult

public Object getResult()


Copyright © 2014 aQute SARL. All rights reserved.