public static void main(String[] args) throws Exception { CommandsTest c = new CommandsTest(); FooCommands foo = new FooCommands(); CLIDriver cliDriver = new CLIDriver(c, foo); cliDriver.start(); }
protected void listCLIMethods() { say("Here are the commands available:"); String[] tempCCIN = CLIReflectionUtil.getCommandsNameList(getCLICommands()); for (int i = 0; i < tempCCIN.length; i++) { say(tempCCIN[i]); } say("To get more information on a command type\n"); say("command --help"); }
public StoreCommands(MyLoggingFacade logger, Store store) { super(logger); setStore(store); setSortable(new BasicSorter()); }
public String getLastArg(){ if(size() == 0){ throw new ArgumentNotFoundException(); } return getArg(size() - 1); }
/** * If this command line has arguments at all. * * @return */ public boolean hasArgs() { return 1 < size(); }
public void load(InputLine inputLine) { if (showHelp(inputLine)) { showLoadHelp(); return; } say("load something"); }
/** * Constructor that sets the indent level for this command processor. Every bit ouf * output will be indented by this amount. * * @param defaultIndent * @param store */ protected StoreCommands(MyLoggingFacade logger, String defaultIndent, Store store) { super(logger); this.defaultIndent = defaultIndent; this.store = store; setSortable(new BasicSorter()); }
/** * Returns the value if it is not empty of a placeholder if it is. * * @param x * @return */ protected String getValue(String x) { return isEmpty(x) ? getPlaceHolder() : x; }
protected void showDeserializeHelp() { say("Deserializes an object into the currnet store overwriting the contents. Cf. serialize."); say("deserialize [-new] -file path"); say("Deserializes the object in the given file. This replaces the object with the given index in the store."); say("The response will give the identifier of the object created."); say("If the -new flag is used, it is assumed that the object should be new. This means that if there is an existing object"); say("with that identifier the operation will fail. If there is no identifier, one will be created."); say("Omitting the -new flag means that any object will be overwritten and if needed, a new identifier will be created"); }
protected void showLoadHelp() { say("loads a configuration from the file. The options are"); say(" load fileName - Assumes a single configuration in the fully qualified name of the file and loads it, setting it active"); say(" load fileName configName - loads the configuration named \"configName\" from the fully qualified name of the file and sets it active"); say("\nExample\n"); say(" load /var/www/config/config.xml default\n"); say("loads the configuration named \"default\" from the file named \"config.xml\" in the directory \"/var/www/config\"\n"); }
@Override public void debug(String x) { say(x); }
protected void shutdown() { say("exiting ..."); /* Don't close the buffered reader since it will close System.in and make it impossible to run another CLI in this JVM. */ }
/** * Prints to the console only if verbose is enabled. * * @param x */ public void sayv(String x) { info(x); }
@Override public String getPrompt() { return getName() + " >"; }
/** * So you can construct the argument list and have this tool use its built in configuration. * @param args */ public void setCommandLine(String[] args){ parseCommandLine(args); } public CommandLine getCommandLine() {
protected void showSerializeHelp() { say("serializes an object and either shows it on the command line or put it in a file. Cf. deserialize."); say("serialize [-file path] index"); say("Serializes the object with the given index. (Note that the index must be the last argument!) " + "It will print it to the command line or save it to the given file,"); say("overwriting the contents of the file."); }
@Override public void error(String x) { say(x); }
@Override public void warn(String x) { say(x); }
protected void showCreateHelp() { say("Create a new entry in the currently active store."); say("Syntax is\n"); say("create [id]\n"); say("where the id is a unique uri which will identify the object. (Note that there is not a lead slash! "); say("Just enter the identifier if you want to set it. Be sure it is a valid uri.) If you do not specify an"); say("identifier, you will be prompted for one. You may also elect to have a new, random one created and assigned."); }