Package alluxio.cli
Interface Command
-
- All Superinterfaces:
java.lang.AutoCloseable
,java.io.Closeable
public interface Command extends java.io.Closeable
An interface for all the commands that can be run from a shell.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
close()
Used to close resources created by commands.java.lang.String
getCommandName()
Gets the command name as input from the shell.java.lang.String
getDescription()
default org.apache.commons.cli.Options
getOptions()
default java.util.Map<java.lang.String,Command>
getSubCommands()
java.lang.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(java.lang.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.
-
-
-
Method Detail
-
getCommandName
java.lang.String getCommandName()
Gets the command name as input from the shell.- Returns:
- the command name
-
getOptions
default org.apache.commons.cli.Options getOptions()
- Returns:
- the supported
Options
of the command
-
hasSubCommand
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.- Returns:
- whether this command has sub-commands
-
getSubCommands
default java.util.Map<java.lang.String,Command> getSubCommands()
- Returns:
- a map from sub-command names to sub-command instances
-
parseAndValidateArgs
default org.apache.commons.cli.CommandLine parseAndValidateArgs(java.lang.String... args) throws InvalidArgumentException
Parses and validates the arguments.- Parameters:
args
- the arguments for the command, excluding the command name- Returns:
- the parsed command line object
- Throws:
InvalidArgumentException
- when arguments are not valid
-
validateArgs
default void validateArgs(org.apache.commons.cli.CommandLine cl) throws InvalidArgumentException
Checks if the arguments are valid or throw InvalidArgumentException.- Parameters:
cl
- the parsed command line for the arguments- Throws:
InvalidArgumentException
- when arguments are not valid
-
run
default int run(org.apache.commons.cli.CommandLine cl) throws AlluxioException, java.io.IOException
Runs the command.- Parameters:
cl
- the parsed command line for the arguments- Returns:
- the result of running the command
- Throws:
AlluxioException
java.io.IOException
-
getUsage
java.lang.String getUsage()
- Returns:
- the usage information of the command
-
getDescription
java.lang.String getDescription()
- Returns:
- the description information of the command
-
close
default void close() throws java.io.IOException
Used to close resources created by commands.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
- if closing resources fails
-
-