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 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(String name, String description)
Print a help entry for a single command.void
printHelpEntry(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:
getDescription
in 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:
getOptions
in 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
-
-