|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectfr.umlv.tatoo.cc.common.main.CommandLineParser<D>
D - type of the user data.public class CommandLineParser<D>
The command line parser :
- permits to add commands by using CommandLineParser(commands) or
addCommand(commands).
Each command contains a description and
register
itself as command for a set of options.
When the command line parser find an option, it calls the associated
command method
execute(option,userData,argument)
with the arguments of the option extracted from the command line.
- permits to directly register an option with the associated command using
registerOption(String, Command, int).
Note : it's better to let the command register itself by adding
command to the command line parser.
- parses arguments using the command descriptions
parse(userData,argumentList) or
parse(userData,arguments.
- returns usage
by delegating to UsageFormatter
| Nested Class Summary | |
|---|---|
static interface |
CommandLineParser.Option
Option information. |
| Constructor Summary | |
|---|---|
CommandLineParser(Command<? super D>... commands)
Create a command line parser with some commands. |
|
CommandLineParser(String prefix,
Command<? super D>... commands)
Create a command line parser with a default option prefix and some commands. |
|
CommandLineParser(String prefix,
UsageFormatter formatter,
Command<? super D>... commands)
Creates a command line parser with a default option prefix, a formatter and some commands. |
|
CommandLineParser(UsageFormatter formatter,
Command<? super D>... commands)
Create a command line parser with a usage formatter and some commands. |
|
| Method Summary | |
|---|---|
void |
addCommands(Command<? super D>... commands)
Add commands to the current command line parser. |
List<? extends String> |
parse(D userData,
List<? extends String> args)
Parse a command line arguments and call the command corresponding to the registered option. |
List<? extends String> |
parse(D userData,
String... args)
Parse a command line arguments and call the command corresponding to the registered option. |
void |
registerOption(String optionName,
Command<? super D> command,
int numberOfArgument)
register an option with a name a command to execute and a number of option argument. |
void |
registerOption(String prefix,
String optionName,
Command<? super D> command,
int numberOfArgument)
register an option with a specific prefix, a name a command to execute and a number of option argument. |
String |
usage(String comment)
Returns the usage of the command line. |
String |
usage(String comment,
int depth,
int optionLength)
Returns the usage of the command line. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CommandLineParser(Command<? super D>... commands)
commands - the commands
public CommandLineParser(String prefix,
Command<? super D>... commands)
prefix - default prefix for option that doesn't specify a prefix,
see addOption(optionName,command,numberOfArgument).commands - the commands
public CommandLineParser(UsageFormatter formatter,
Command<? super D>... commands)
CommandLineParser("",formatter,commands.
formatter - commands - the commands
public CommandLineParser(String prefix,
UsageFormatter formatter,
Command<? super D>... commands)
prefix - the default prefix for optionformatter - the usage formattercommands - the commandsaddCommands(Command[])| Method Detail |
|---|
public void addCommands(Command<? super D>... commands)
register itself
their options.
commands -
public void registerOption(String optionName,
Command<? super D> command,
int numberOfArgument)
OptionRegistryCommandLineParser(defaultPrefix,usageFormatter,commands).
registerOption in interface OptionRegistry<D>optionName - the name of the option.command - the command associated with the option.numberOfArgument - hte number of argument of the option.
public void registerOption(String prefix,
String optionName,
Command<? super D> command,
int numberOfArgument)
OptionRegistry
registerOption in interface OptionRegistry<D>prefix - the specific prefix of the option.optionName - the name of the option.command - the command associated with the option.numberOfArgument - hte number of argument of the option.OptionRegistry.registerOption(String, Command, int)
public List<? extends String> parse(D userData,
String... args)
throws IllegalCommandLineArgumentException
doIt(optionName,userData,optionArguments)
of the associated command is called with the user data.
userData - the user data.args - arguments received by the method main().
IllegalCommandLineArgumentException - if an argument starts with
a registered prefix
or the default prefix
and is not a registered option.
public List<? extends String> parse(D userData,
List<? extends String> args)
throws IllegalCommandLineArgumentException
doIt(optionName,userData,optionArguments)
of the associated command is called with the user data.
userData - the user data.args - arguments received by the method main().
IllegalCommandLineArgumentException - if an argument starts with
a registered prefix
or the default prefix
and is not a registered option.public String usage(String comment)
usage(comment,DEFAULT_DEPTH,DEFAULT_LENGTH).
comment - general comment of the program.
UsageFormatter.usage(String, Map, int, int),
UsageFormatter.DEFAULT_DEPTH,
UsageFormatter.DEFAULT_OPTION_LENGTH
public String usage(String comment,
int depth,
int optionLength)
comment - general comment of the program.depth - shift in character for each line of the usageoptionLength - size in caracter reserved for printing option information
UsageFormatter.usage(String, Map, int, int)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||