T
- The class that contains all the commands.public class InteractiveShell<T> extends Object
Additionally, it also prints documentation if necessary.
Usage: Create a class called AllCommands
class AllCommands {
@CommandDescription(description = "Does foo to bar");
public static Foo(String bar) {
...
}
}
Create the main function somewhere
public static void main(String[] args) throws Exception { InteractiveShell<AllCommands> tester = new InteractiveShell<AllCommands>(AllCommands.class); if (args.length == 0) tester.showDocumentation(); else tester.runCommand(args); }
Now, command line options can be added to the program by adding static functions to AllCommands.
Constructor and Description |
---|
InteractiveShell(Class<T> className)
Create a new interactive shell for type T
|
Modifier and Type | Method and Description |
---|---|
void |
runCommand(String[] args)
Runs a command.
|
void |
showDocumentation()
Displays the available static commands along with their documentation.
|
public void showDocumentation()
public void runCommand(String[] args) throws Exception
The command is specified by the first element of the argument and its parameters are the rest of the elements.
Note: This demands that all the parameters should be strings.
args
- An array of strings. The name of the command should be the first element and its
parameters should follow.Exception
Copyright © 2017. All rights reserved.