public abstract class Command extends Object
Parent class for all commands.
Each concrete command class should be like singleton (even though without a static getInstance()
method),
i.e. a command should only be instantiated when registering.
Constructor and Description |
---|
Command(String name) |
Command(String name,
String description,
String usage) |
Command(String name,
UIText description,
UIText usage) |
Modifier and Type | Method and Description |
---|---|
void |
execute(CommandIssuer issuer,
String line)
Trigger this command.
|
List<String> |
getAliases()
Aliases of this command.
|
String[] |
getArgs()
The
argument line line split at whitespaces |
String |
getArgsLine()
The exact line of command without the command name.
|
UIText |
getDescription()
This command's description, which can be displayed to users.
|
String |
getName()
A unique
String identifier of this command. |
UIText |
getUsage()
This command's usage, which can be displayed to users.
|
org.apache.commons.cli.CommandLine |
parseArgs(org.apache.commons.cli.Options options)
Parse command arguments using
Commons CLI |
org.apache.commons.cli.CommandLine |
parseArgs(org.apache.commons.cli.Options options,
boolean stopAtNonOption)
Parse command arguments using
Commons CLI |
protected abstract void |
run()
Implementation of the command.
|
Command |
setDescription(UIText description)
This command's description, which can be displayed to users.
|
Command |
setUsage(UIText usage)
This command's usage, which can be displayed to users.
|
public Command(String name)
public final void execute(CommandIssuer issuer, String line)
Trigger this command.
issuer
- the CommandIssuer
who issued this command.line
- the rest of the arguments in the command.protected abstract void run()
Implementation of the command.
Arguments for this execution can be found using these methods:
getArgsLine()
,
getArgs()
,
parseArgs(Options)
public String getArgsLine()
The exact line of command without the command name.
public String[] getArgs()
The argument line
line split at whitespaces
public org.apache.commons.cli.CommandLine parseArgs(org.apache.commons.cli.Options options) throws org.apache.commons.cli.ParseException
Commons CLI
options
- Options to look forCommandLine
result from Commons CLI
org.apache.commons.cli.ParseException
- if CommandLineParser
encountered problems parsing argumentspublic org.apache.commons.cli.CommandLine parseArgs(org.apache.commons.cli.Options options, boolean stopAtNonOption) throws org.apache.commons.cli.ParseException
Commons CLI
options
- Options to look forstopAtNonOption
- Stop parsing options if there is an unrecognized optionCommandLine
result from Commons CLI
org.apache.commons.cli.ParseException
- if CommandLineParser
encountered problems parsing argumentspublic UIText getDescription()
This command's description, which can be displayed to users.
public Command setDescription(UIText description)
This command's description, which can be displayed to users.
public UIText getUsage()
This command's usage, which can be displayed to users.
public Command setUsage(UIText usage)
This command's usage, which can be displayed to users.
Copyright © 2016. All rights reserved.