From: SVN by r. <sv...@ca...> - 2007-10-08 15:29:39
|
Author: rotman Date: 2007-10-08 17:29:40 +0200 (Mon, 08 Oct 2007) New Revision: 172 Modified: src/main/java/nl/improved/sqlclient/SQLShell.java Log: Implement commandline connect Modified: src/main/java/nl/improved/sqlclient/SQLShell.java =================================================================== --- src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-08 15:18:39 UTC (rev 171) +++ src/main/java/nl/improved/sqlclient/SQLShell.java 2007-10-08 15:29:40 UTC (rev 172) @@ -25,7 +25,6 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import javax.sound.midi.SysexMessage; import jcurses.widgets.Window; import jcurses.system.InputChar; import jcurses.system.Toolkit; @@ -281,7 +280,7 @@ debug("Unknown character: "+ inp.getCode()); } else if (inp.toString().equals("")) { //Ctrl+D if (commandLines.getCommandString().length() == 0) { //Quit on empty commandline, ignore otherwise - new QuitCommand().execute(new SQLCommand()); + executeCommand(new InputCommand("quit")); } } else { if (inp.getCharacter() == '\n') { @@ -1077,8 +1076,42 @@ "Note that all statements must be terminated with ';' (sql statements as well as connect statements or spool)"; } } + + /** + * Command class to execute a 'custom command'. + * this makes it possible to have 'automated' commands executed. + * E.g.: + * executeCommand(new InputCommand("connect")); + * will eventually execute the Connect command. + */ + private static class InputCommand extends SQLCommand { + private StringBuilder command; + + public InputCommand(String command) { + this.command = new StringBuilder(command); + } + + @Override + public String getUntrimmedCommandString() { + return command.toString(); + } + @Override + public List<StringBuilder> getEditableLines() { + return Arrays.asList(new StringBuilder[]{command}); + } + @Override + public List<? extends CharSequence> getLines() { + return Arrays.asList(new StringBuilder[]{command}); + } + } + public static void main(String[] args) { SQLShell shell = new SQLShell(); shell.show(); + + //Interpret first argument as a connect argument + if (args.length > 0) { + shell.executeCommand(new InputCommand("connect "+args[0])); + } } } |