public class CommandManager extends Object implements Command
global, missingFileError| Constructor and Description |
|---|
CommandManager()
Initialze the command.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCommand(String commandName,
Command command)
Add a new command to this manager.
|
CommandState |
execute(CommandState state,
String[] args)
Given an input state and command-line arguments, execute one or more commands.
|
CommandState |
executeCommand(CommandState state,
List<String> globalOptionArgs,
List<String> arguments)
Given an input state, global option strings, and remaining command-line argument strings, use
as many arguments as needed to execute a single command.
|
String |
getDescription()
Brief description of the command.
|
String |
getName()
Name of the command.
|
List<String> |
getOptionArgs(org.apache.commons.cli.Options options,
List<String> arguments)
Given some Options and some arguments, collect all the options until the first non-option
argument, then remove those used argument strings from the arguments list and return the used
arguments as a new list.
|
org.apache.commons.cli.Options |
getOptions()
Command-line options for the command.
|
String |
getUsage()
Command-line usage for the command.
|
void |
main(String[] args)
Given command-line arguments, execute one or more commands.
|
void |
printHelp()
Print general help plus a list of available commands.
|
void |
printHelpEntry(Map.Entry<String,Command> entry)
Print a help entry for a single command.
|
void |
printHelpEntry(String name,
String description)
Print a help entry for a single command.
|
public String getName()
public String getDescription()
getDescription in interface Commandpublic String getUsage()
public org.apache.commons.cli.Options getOptions()
getOptions in interface Commandpublic void addCommand(String commandName, Command command)
commandName - the of the command (one word)command - the Command object to registerpublic List<String> getOptionArgs(org.apache.commons.cli.Options options, List<String> arguments) throws org.apache.commons.cli.ParseException
options - the options to collectarguments - a list of remaining command-line arguments; used option strings are removed
from this listorg.apache.commons.cli.ParseException - if command line cannot be parsedpublic void main(String[] args)
public CommandState execute(CommandState state, String[] args) throws Exception
public CommandState executeCommand(CommandState state, List<String> globalOptionArgs, List<String> arguments) throws Exception
state - the state from the previous command, or nullglobalOptionArgs - a list of global option stringsarguments - the list of remaining command-line arguments; any arguments that are used will
be removed from this listException - on any problemspublic void printHelp()
public void printHelpEntry(Map.Entry<String,Command> entry)
entry - an entry from the map of commandsCopyright © 2015–2020. All rights reserved.