public interface Command extends Comparable<Command>, Closeable
| 限定符和类型 | 方法和说明 |
|---|---|
default void |
close()
Used to close resources created by commands.
|
default int |
compareTo(Command that) |
String |
getCommandName()
Gets the command name as input from the shell.
|
String |
getDescription() |
default org.apache.commons.cli.Options |
getOptions() |
default Map<String,Command> |
getSubCommands() |
String |
getUsage() |
default boolean |
hasSubCommand()
If a command has sub-commands, the first argument should be the sub-command's name,
all arguments and options will be parsed for the sub-command.
|
default org.apache.commons.cli.CommandLine |
parseAndValidateArgs(String... args)
Parses and validates the arguments.
|
default int |
run(org.apache.commons.cli.CommandLine cl)
Runs the command.
|
default void |
validateArgs(org.apache.commons.cli.CommandLine cl)
Checks if the arguments are valid or throw InvalidArgumentException.
|
String getCommandName()
default int compareTo(Command that)
compareTo 在接口中 Comparable<Command>default org.apache.commons.cli.Options getOptions()
Options of the commanddefault boolean hasSubCommand()
default Map<String,Command> getSubCommands()
default org.apache.commons.cli.CommandLine parseAndValidateArgs(String... args) throws IllegalArgumentException
args - the arguments for the command, excluding the command nameIllegalArgumentException - when arguments are not validdefault void validateArgs(org.apache.commons.cli.CommandLine cl)
throws IllegalArgumentException
cl - the parsed command line for the argumentsIllegalArgumentException - when arguments are not validdefault int run(org.apache.commons.cli.CommandLine cl)
throws IOException
cl - the parsed command line for the argumentsIOExceptionString getUsage()
String getDescription()
default void close()
throws IOException
close 在接口中 AutoCloseableclose 在接口中 CloseableIOException - if closing resources failsCopyright © 2017–2025 The Apache Software Foundation. All rights reserved.