// Publish the methods in the Console class itself for testing purposes.
console.addCommandProvider(inspector = new ObjectInspector(console));
// Add help command
Command helpCommand = new Console.Command() {
private static final long serialVersionUID = 2838665604270727844L;
public String getUsage(Console console, String[] argv) {
return argv[0] + " <command>";
}
public Object execute(Console console, String[] argv)
throws Exception {
if (argv.length == 2) {
Command hc = console.getCommand(argv[1]);
ArrayList<String> cmdArgv = new ArrayList<String>(Arrays
.asList(argv));
cmdArgv.remove(0);
return "Usage: "
+ hc.getUsage(console, cmdArgv
.toArray(new String[] {}));
}
return listAvailableCommands();
}
};
// Bind the same command with multiple names
console.addCommand("help", helpCommand);
console.addCommand("info", helpCommand);
console.addCommand("man", helpCommand);
// #
// # 2
Command systemCommand = new Command() {
private static final long serialVersionUID = -5733237166568671987L;
public Object execute(Console console, String[] argv)
throws Exception {
Process p = Runtime.getRuntime().exec(argv);