public abstract class JSAPArgsParsingCommandPlugin extends AbstractCommandPlugin implements CommandPlugin
CommandPlugin which uses JSAP
to parse command arguments and provide helpful error messages.
The parser can be configured when @{link configureArgsParser(JSAP) is called.
JSAP has a 'fluid' API where methods are chained together to configure a specific parameter.
To register a parameter:
argsParser.registerParameter(new UnflaggedOption("my-option").setRequired(true).setHelp("a helpful message about this arg"));
To set a 'port' flag which is used via the command arguments as either '-port XYZ' or '-p XYZ' use:
argsParser.registerParameter(new FlaggedOption("port").setShortFlag('p').setLongFlag("port").setRequired(false).setHelp("the port number"));
Command arguments will be automatically parsed and provided when doCommand(JSAPResult) is called. Argument values are accessed
by name, for example:
parsedArgs.getString("some-arg");
parsedArgs.getBoolean("some-arg");
| Constructor and Description |
|---|
JSAPArgsParsingCommandPlugin() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
configureArgsParser(com.martiansoftware.jsap.JSAP argsParser) |
protected abstract int |
doCommand(com.martiansoftware.jsap.JSAPResult parsedArgs) |
int |
doCommand(java.lang.String... args)
Runs the command using the provided user arguments.
|
java.lang.String |
getCommandHelp()
Returns a detailed help message that describes the various parameters the command provides, and how they are used.
|
java.lang.String |
getCommandUsage()
Returns a usage message that shows the user an example of how the command parameters are used.
|
castTo, close, equals, getPluginClass, instanceOfclone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetCommandDescription, getCommandNamecastTo, close, getPluginClass, instanceOf, setBRJSprotected abstract void configureArgsParser(com.martiansoftware.jsap.JSAP argsParser)
throws com.martiansoftware.jsap.JSAPException
com.martiansoftware.jsap.JSAPExceptionprotected abstract int doCommand(com.martiansoftware.jsap.JSAPResult parsedArgs)
throws CommandArgumentsException,
CommandOperationException
public final java.lang.String getCommandUsage()
CommandPluginNote: This method doesn't need to be implemented if you've chosen to extend JSAPArgsParsingCommandPlugin.
getCommandUsage in interface CommandPluginpublic java.lang.String getCommandHelp()
CommandPluginNote: This method doesn't need to be implemented if you've chosen to extend JSAPArgsParsingCommandPlugin.
getCommandHelp in interface CommandPluginpublic final int doCommand(java.lang.String... args)
throws CommandArgumentsException,
CommandOperationException
CommandPlugindoCommand in interface CommandPluginargs - The list of arguments provided by the user.CommandArgumentsException - if any invalid arguments were provided.CommandOperationException - if a problem was encountered while running the command.