From 4bd53349774beecbf235f1589a3d9168b04a17f5 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 2 May 2014 23:38:34 +0200 Subject: Accept multiple commands (for automation) Instead of `./run.sh shell target +file`, and then manually running add and commit, you can now use: ./run.sh shell 'target +file' 'add samsung' commit Quoting is necessary because of the spaces. --- src/main/TweetShell.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/main/TweetShell.java') diff --git a/src/main/TweetShell.java b/src/main/TweetShell.java index 818c693..d292c9a 100644 --- a/src/main/TweetShell.java +++ b/src/main/TweetShell.java @@ -126,19 +126,24 @@ public class TweetShell implements TwitterApi.PinSupplier { printPrompt(); while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); - String[] args = line.split("\\s+", 2); - if (!args[0].isEmpty()) { - // non-empty command, let's see whether it makes sense? - if (!execute(args)) { - // requested to terminate - break; - } + if (!execute(line)) { + // requested to terminate + break; } // print prompt for reading next line printPrompt(); } } + public boolean execute(String cmd) { + String[] args = cmd.trim().split("\\s+", 2); + if (!args[0].isEmpty()) { + // non-empty command, let's see whether it makes sense? + return execute(args); + } + return true; + } + /** * Executes a command with optional parameters. * -- cgit v1.2.1