Skip to content
Snippets Groups Projects
Commit 496d27f8 authored by Nadav Har'El's avatar Nadav Har'El
Browse files

CLI: Allow running a single command non-interactively

Added the possibility to pass to cli.jar a command, which it runs instead
of taking commands interactively. Note that the initialization script is
run before the given command.

After this patch,

        scripts/run.py -e "java.so -jar /java/cli.jar"

Continues to run the interactive command line editor loop, as before.
But additionally, one can do:

        scripts/run.py -e "java.so -jar /java/cli.jar ls"

To run just the command "ls" and exit - exactly as if the user would type
this command on the command line and exit the VM.

The given command can be, of course, much longer. For example to run Jetty
after the CLI's normal initialization script, the following monster can
be used:

scripts/run.py -n -e "java.so -jar /java/cli.jar java -classpath /jetty/* org.eclipse.jetty.xml.XmlConfiguration /jetty/jetty.xml"

(Funny how a single command should say "java" 3 times and "jetty" 4 times :-))
parent 01cb7973
No related branches found
No related tags found
No related merge requests found
...@@ -286,5 +286,10 @@ update_prompt(); ...@@ -286,5 +286,10 @@ update_prompt();
load("/console/init.js"); load("/console/init.js");
// Main loop mainargs = com.cloudius.cli.main.RhinoCLI._args;
main_loop(); if (mainargs.length) {
invoke(mainargs);
} else {
// Main loop
main_loop();
}
...@@ -11,6 +11,8 @@ public class RhinoCLI { ...@@ -11,6 +11,8 @@ public class RhinoCLI {
public static Scriptable _scope; public static Scriptable _scope;
public static Context _cx; public static Context _cx;
public static String[] _args;
// //
// Invoke the cli.js file take care of exposing all scriptable objects // Invoke the cli.js file take care of exposing all scriptable objects
...@@ -23,6 +25,8 @@ public class RhinoCLI { ...@@ -23,6 +25,8 @@ public class RhinoCLI {
global.init(_cx); global.init(_cx);
_scope = ScriptableObject.getTopLevelScope(global); _scope = ScriptableObject.getTopLevelScope(global);
_args = args;
FileReader cli_js = new FileReader("/console/cli.js"); FileReader cli_js = new FileReader("/console/cli.js");
_cx.evaluateReader(_scope, cli_js, "cli.js", 1, null); _cx.evaluateReader(_scope, cli_js, "cli.js", 1, null);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment