public abstract class Command extends Object
Constructor and Description |
---|
Command(String[] commandPath)
Default Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addArgument(CommandArgument argument)
Adds a command argument to the argument list
|
void |
addOption(char c,
String description,
String longOpt)
Adds a command option to CLI command
|
void |
addOption(char c,
String description,
String longOpt,
boolean hasArg,
String argName)
Adds a command option to CLI command
|
CommandArgumentResult |
checkArguments(PrintStream out,
List<String> args)
Checks a Command's argument list to determine if the command is valid
|
boolean |
confirm(Location location) |
boolean |
confirm(Location location,
String message)
This method confirms an action
|
int |
defaultArgumentResultHandler(PrintStream out,
CommandArgumentResult argResult)
A default result handler for handling typical HELP and FAIL cases
|
abstract int |
execute(Location location,
List<String> args)
The abstract call to execute the Command
|
protected List<CommandArgument> |
getCommandArgumentList() |
org.apache.commons.cli.CommandLine |
getCommandLine() |
protected org.apache.commons.cli.Options |
getCommandLineOptions() |
String[] |
getCommandPath() |
jline.console.completer.Completer |
getCompleter(Location currentLocation) |
abstract String |
getUsageDescription() |
String |
getUsageExample() |
String |
getUsageHeader() |
int |
handleBooleanResponse(PrintStream out,
boolean success,
String failureMessage)
Handles the boolean responses for commands from AlpacaLibrary
|
int |
handleResponse(PrintStream out,
Response r) |
boolean |
isCompleteArgumentList(List<String> providedArgs)
Checks if a set of arguments is complete and prints the remaining items
that need to be entered.
|
void |
printHelp(PrintStream out,
List<String> providedArgs)
Print details on remaining arguments for a command
|
void |
println(PrintStream out,
String s)
This method determines how locations print information to the console
|
void |
printUsage(PrintStream out)
Outputs the usage header, description, and options.
|
public Command(String[] commandPath)
commandPath
- The command path for the command.public void addArgument(CommandArgument argument) throws AlpacaException
argument
- The argumentAlpacaException
- Thrown if adding a required argument after an optional argument.public void addOption(char c, String description, String longOpt)
c
- The short optdescription
- The descriptionlongOpt
- The long optpublic void addOption(char c, String description, String longOpt, boolean hasArg, String argName)
c
- The short optdescription
- The descriptionlongOpt
- The long opthasArg
- Whether the command has an attached argumentpublic CommandArgumentResult checkArguments(PrintStream out, List<String> args) throws AlpacaException
args
- The argument listCommandArgumentResult
value.AlpacaException
- Thrown if the arguments cannot be parsed.public int defaultArgumentResultHandler(PrintStream out, CommandArgumentResult argResult) throws AlpacaException
argResult
- The CommandArgumentResult for parsing the command line arguments.AlpacaException
- Thrown if an error occurs while printing usage.public abstract int execute(Location location, List<String> args) throws AlpacaException
location
- The location executing the command.args
- The command line arguments.AlpacaException
- Thrown if an unexpected error occurs while running the command.protected List<CommandArgument> getCommandArgumentList()
public org.apache.commons.cli.CommandLine getCommandLine()
protected org.apache.commons.cli.Options getCommandLineOptions()
public String[] getCommandPath()
public jline.console.completer.Completer getCompleter(Location currentLocation)
public String getUsageExample()
public abstract String getUsageDescription()
public String getUsageHeader()
public int handleBooleanResponse(PrintStream out, boolean success, String failureMessage)
public int handleResponse(PrintStream out, Response r) throws AlpacaException
AlpacaException
public boolean isCompleteArgumentList(List<String> providedArgs)
public void printHelp(PrintStream out, List<String> providedArgs)
public void println(PrintStream out, String s)
public void printUsage(PrintStream out)
out
- The print stream to write.public boolean confirm(Location location)
Copyright © 2017 ECG. All rights reserved.