Package org.obolibrary.robot
Class CommandManager
- java.lang.Object
-
- org.obolibrary.robot.CommandManager
-
- All Implemented Interfaces:
Command
public class CommandManager extends Object implements Command
Execute collections of commands.- Author:
- James A. Overton
-
-
Field Summary
-
Fields inherited from interface org.obolibrary.robot.Command
global, missingFileError
-
-
Constructor Summary
Constructors Constructor Description CommandManager()Initialze the command.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCommand(String commandName, Command command)Add a new command to this manager.CommandStateexecute(CommandState state, String[] args)Given an input state and command-line arguments, execute one or more commands.CommandStateexecuteCommand(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.StringgetDescription()Brief description of the command.StringgetName()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.OptionsgetOptions()Command-line options for the command.StringgetUsage()Command-line usage for the command.voidmain(String[] args)Given command-line arguments, execute one or more commands.voidprintHelp()Print general help plus a list of available commands.voidprintHelpEntry(String name, String description)Print a help entry for a single command.voidprintHelpEntry(Map.Entry<String,Command> entry)Print a help entry for a single command.
-
-
-
Method Detail
-
getName
public String getName()
Name of the command.
-
getDescription
public String getDescription()
Brief description of the command.- Specified by:
getDescriptionin interfaceCommand- Returns:
- description
-
getUsage
public String getUsage()
Command-line usage for the command.
-
getOptions
public org.apache.commons.cli.Options getOptions()
Command-line options for the command.- Specified by:
getOptionsin interfaceCommand- Returns:
- options
-
addCommand
public void addCommand(String commandName, Command command)
Add a new command to this manager.- Parameters:
commandName- the of the command (one word)command- the Command object to register
-
getOptionArgs
public List<String> getOptionArgs(org.apache.commons.cli.Options options, List<String> arguments) throws org.apache.commons.cli.ParseException
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. WARN: Mutates the `arguments` list.- Parameters:
options- the options to collectarguments- a list of remaining command-line arguments; used option strings are removed from this list- Returns:
- the list of used argument strings
- Throws:
org.apache.commons.cli.ParseException- if command line cannot be parsed
-
main
public void main(String[] args)
Given command-line arguments, execute one or more commands.
-
execute
public CommandState execute(CommandState state, String[] args) throws Exception
Given an input state and command-line arguments, execute one or more commands.
-
executeCommand
public CommandState executeCommand(CommandState state, List<String> globalOptionArgs, List<String> arguments) throws Exception
Given an input state, global option strings, and remaining command-line argument strings, use as many arguments as needed to execute a single command. The arguments used by the command are removed from the arguments list, which can then be used to execute further commands.- Parameters:
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 list- Returns:
- the state that results from this command
- Throws:
Exception- on any problems
-
printHelp
public void printHelp()
Print general help plus a list of available commands.
-
printHelpEntry
public void printHelpEntry(Map.Entry<String,Command> entry)
Print a help entry for a single command.- Parameters:
entry- an entry from the map of commands
-
-