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 2015/08/21 15:46:19 UTC

[2/2] incubator-tinkerpop git commit: Added docs on the ScriptExecutor.

Added docs on the ScriptExecutor.


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

Branch: refs/heads/tp30
Commit: 1df2012f281535dd8675618562e8a2d0c61f6bf0
Parents: 4d032c2
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Aug 21 09:45:26 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Aug 21 09:45:26 2015 -0400

----------------------------------------------------------------------
 docs/src/gremlin-applications.asciidoc | 46 +++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1df2012f/docs/src/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/gremlin-applications.asciidoc b/docs/src/gremlin-applications.asciidoc
index c82e68b..cf63054 100644
--- a/docs/src/gremlin-applications.asciidoc
+++ b/docs/src/gremlin-applications.asciidoc
@@ -183,6 +183,52 @@ CAUTION: Plugins must be compatible with the version of the Gremlin Console (or
 
 TIP: It is possible to manage plugin activation and deactivation by manually editing the `ext/plugins.txt` file which contains the class names of the "active" plugins.  It is also possible to clear dependencies added by `:install` by deleting them from the `ext` directory.
 
+Script Executor
+~~~~~~~~~~~~~~~
+
+For automated tasks and batch executions of Gremlin, it can be useful to execute Gremlin scripts from the command line.  Consider the following file named `gremlin.groovy`:
+
+[source,groovy]
+----
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.*
+graph = TinkerFactory.createModern()
+g = graph.traversal()
+g.V().each { println it }
+----
+
+This script creates the toy graph and then iterates through all its vertices printing each to the system out.  Note that under this approach, "imports" need to be explicitly defined (except for "core" TinkerPop classes).  In addition, plugins and other dependencies should already be "installed" via console commands which cannot be used with this mode of execution.  To execute this script from the command line, `gremlin.sh` has the `-e` option used as follows:
+
+[source,bash]
+----
+$ bin/gremlin.sh -e gremlin.groovy
+v[1]
+v[2]
+v[3]
+v[4]
+v[5]
+v[6]
+----
+
+It is also possible to pass arguments to scripts.  Any parameters following the file name specification are treated as arguments to the script. They are collected into a list and passed in as a variable called "args".  The following Gremlin script is exactly like the previous one, but it makes use of the "args" option to filter the vertices printed to system out:
+
+[source,groovy]
+----
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.*
+graph = TinkerFactory.createModern()
+g = graph.traversal()
+g.V().has('name',args[0]).each { println it }
+----
+
+When executed from the command line a parameter can be supplied:
+
+[source,bash]
+----
+$ bin/gremlin.sh -e gremlin.groovy marko
+v[1]
+$ bin/gremlin.sh -e gremlin.groovy vadas
+v[2]
+----
+
 [[gremlin-server]]
 Gremlin Server
 --------------