You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/12/08 20:41:24 UTC

tinkerpop git commit: TINKERPOP-1851 Minor fix to allow long forms of -e and -i to work

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1851 [created] d217b821b


TINKERPOP-1851 Minor fix to allow long forms of -e and -i to work

There was some special handling of the short forms that wasn't accounted for with the long forms. Pretty simple fix. Added lots of tests to ensure the different options were covered.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/d217b821
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d217b821
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d217b821

Branch: refs/heads/TINKERPOP-1851
Commit: d217b821b30f34649b876fa1086bb6b21d364bf8
Parents: a883746
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Dec 8 15:40:13 2017 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Dec 8 15:40:13 2017 -0500

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../tinkerpop/gremlin/console/Console.groovy    |  6 +-
 .../src/test/python/tests/test_console.py       | 68 ++++++++++++++++++++
 3 files changed, 72 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d217b821/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 2f1a5c6..7de8639 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -27,6 +27,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 * Documented the recommended method for constructing DSLs with Gremlin.Net.
 * Provided a method to configure detachment options with `EventStrategy`.
 * Fixed a race condition in `TinkerIndex`.
+* Fixed bug in handling of the long forms of `-e` and `-i` (`--execute` and `--interactive` respectively) for Gremlin Console.
 * Fixed bug in `LambdaRestrictionStrategy` where traversals using `Lambda` scripts weren't causing the strategy to trigger.
 * Improved error messaging for bytecode deserialization errors in Gremlin Server.
 * Fixed an `ArrayOutOfBoundsException` in `hasId()` for the rare situation when the provided collection is empty.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d217b821/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
index 59de0b3..5eb5039 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy
@@ -477,7 +477,7 @@ class Console {
         if (args.length == 1 && !args[0].startsWith("-")) {
             new Console(io, [[args[0]]], true)
         } else {
-            def scriptAndArgs = parseArgs(options.e ? "-e" : "-i", args, cli)
+            def scriptAndArgs = parseArgs(options.e ? ["-e", "--execute"] : ["-i", "--interactive"], args, cli)
             new Console(io, scriptAndArgs, !options.e)
         }
     }
@@ -487,10 +487,10 @@ class Console {
      * argument list to allow for multiple {@code -e} and {@code -i} values and parses such parameters into a list
      * of lists where the inner list is a script file and its arguments.
      */
-    private static List<List<String>> parseArgs(final String option, final String[] args, final CliBuilder cli) {
+    private static List<List<String>> parseArgs(final List<String> options, final String[] args, final CliBuilder cli) {
         def parsed = []
         for (int ix = 0; ix < args.length; ix++) {
-            if (args[ix] == option) {
+            if (args[ix] in options) {
                 // increment the counter to move past the option that was found. should now be positioned on the
                 // first argument to that option
                 ix++

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d217b821/gremlin-console/src/test/python/tests/test_console.py
----------------------------------------------------------------------
diff --git a/gremlin-console/src/test/python/tests/test_console.py b/gremlin-console/src/test/python/tests/test_console.py
index 407b563..67e1a9e 100644
--- a/gremlin-console/src/test/python/tests/test_console.py
+++ b/gremlin-console/src/test/python/tests/test_console.py
@@ -41,6 +41,14 @@ class TestConsole(object):
         TestConsole._expect_prompt(child)
         TestConsole._close(child)
 
+    def test_just_dash_dash_interactive(self):
+        child = pexpect.spawn(TestConsole.gremlinsh + "--interactive x.script")
+        TestConsole._expect_gremlin_header(child)
+        TestConsole._send(child, "x")
+        child.expect("==>2\r\n")
+        TestConsole._expect_prompt(child)
+        TestConsole._close(child)
+
     def test_dash_i_with_args(self):
         child = pexpect.spawn(TestConsole.gremlinsh + "-i y.script 1 2 3")
         TestConsole._expect_gremlin_header(child)
@@ -49,6 +57,14 @@ class TestConsole(object):
         TestConsole._expect_prompt(child)
         TestConsole._close(child)
 
+    def test_dash_dash_interactive_with_args(self):
+        child = pexpect.spawn(TestConsole.gremlinsh + "--interactive y.script 1 2 3")
+        TestConsole._expect_gremlin_header(child)
+        TestConsole._send(child, "y")
+        child.expect("==>6\r\n")
+        TestConsole._expect_prompt(child)
+        TestConsole._close(child)
+
     def test_dash_i_multiple_scripts(self):
         child = pexpect.spawn(TestConsole.gremlinsh + "-i y.script 1 2 3 -i x.script -i \"z.script x -i --color -D\"")
         TestConsole._expect_gremlin_header(child)
@@ -63,16 +79,54 @@ class TestConsole(object):
         TestConsole._expect_prompt(child)
         TestConsole._close(child)
 
+    def test_dash_dash_interactive_multiple_scripts(self):
+        child = pexpect.spawn(TestConsole.gremlinsh + "--interactive y.script 1 2 3 --interactive x.script -i \"z.script x -i --color -D\"")
+        TestConsole._expect_gremlin_header(child)
+        TestConsole._send(child, "y")
+        child.expect("==>6\r\n")
+        TestConsole._expect_prompt(child)
+        TestConsole._send(child, "x")
+        child.expect("==>2\r\n")
+        TestConsole._expect_prompt(child)
+        TestConsole._send(child, "z")
+        child.expect("==>argument=\[x, -i, --color, -D\]\r\n")
+        TestConsole._expect_prompt(child)
+        TestConsole._close(child)
+
+    def test_mixed_interactive_long_short_opts_with_multiple_scripts(self):
+        child = pexpect.spawn(TestConsole.gremlinsh + "--interactive y.script 1 2 3 --interactive x.script -i \"z.script x -i --color -D\"")
+        TestConsole._expect_gremlin_header(child)
+        TestConsole._send(child, "y")
+        child.expect("==>6\r\n")
+        TestConsole._expect_prompt(child)
+        TestConsole._send(child, "x")
+        child.expect("==>2\r\n")
+        TestConsole._expect_prompt(child)
+        TestConsole._send(child, "z")
+        child.expect("==>argument=\[x, -i, --color, -D\]\r\n")
+        TestConsole._expect_prompt(child)
+        TestConsole._close(child)
+
     def test_just_dash_e(self):
         child = pexpect.spawn(TestConsole.gremlinsh + "-e x-printed.script")
         child.expect("2\r\n")
         TestConsole._close(child)
 
+    def test_just_dash_dash_execute(self):
+        child = pexpect.spawn(TestConsole.gremlinsh + "--execute x-printed.script")
+        child.expect("2\r\n")
+        TestConsole._close(child)
+
     def test_dash_e_with_args(self):
         child = pexpect.spawn(TestConsole.gremlinsh + "-e y-printed.script 1 2 3")
         child.expect("6\r\n")
         TestConsole._close(child)
 
+    def test_dash_dash_execute_with_args(self):
+        child = pexpect.spawn(TestConsole.gremlinsh + "--execute y-printed.script 1 2 3")
+        child.expect("6\r\n")
+        TestConsole._close(child)
+
     def test_dash_e_multiple_scripts(self):
         child = pexpect.spawn(TestConsole.gremlinsh + "-e y-printed.script 1 2 3 -e x-printed.script -e \"z-printed.script x -e --color -D\"")
         child.expect("6\r\n")
@@ -80,6 +134,20 @@ class TestConsole(object):
         child.expect("argument=\[x, -e, --color, -D\]\r\n")
         TestConsole._close(child)
 
+    def test_dash_dash_execute_multiple_scripts(self):
+        child = pexpect.spawn(TestConsole.gremlinsh + "--execute y-printed.script 1 2 3 --execute x-printed.script --execute \"z-printed.script x -e --color -D\"")
+        child.expect("6\r\n")
+        child.expect("2\r\n")
+        child.expect("argument=\[x, -e, --color, -D\]\r\n")
+        TestConsole._close(child)
+
+    def test_mixed_execute_long_short_opts_with_multiple_scripts(self):
+        child = pexpect.spawn(TestConsole.gremlinsh + "--execute y-printed.script 1 2 3 -e x-printed.script --execute \"z-printed.script x -e --color -D\"")
+        child.expect("6\r\n")
+        child.expect("2\r\n")
+        child.expect("argument=\[x, -e, --color, -D\]\r\n")
+        TestConsole._close(child)
+
     def test_no_mix_dash_i_and_dash_e(self):
         child = pexpect.spawn(TestConsole.gremlinsh + "-i y.script 1 2 3 -i x.script -e \"z.script x -i --color -D\"")
         child.expect("-i and -e options are mutually exclusive - provide one or the other")