Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added -v option

  • Loading branch information...
commit daa982e37f29dbbb9d1275377e363dc73294827d 1 parent fd14839
@micha authored
Showing with 11 additions and 1 deletion.
  1. +3 −0  README.markdown
  2. +8 −1 jsawk
View
3  README.markdown
@@ -74,6 +74,9 @@ Usage
'-q' options are specified then each query will be performed in
turn, in the order in which they appeared on the command line.
+ -v <name=value>
+ Set global variable `name` to `value` in the script environment.
+
-f <file>
Load and run the specified JavaScript file prior to processing
JSON. This option can be specified multiple times to load multiple
View
9 jsawk
@@ -961,7 +961,7 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
var usage = function() {
err("Usage: jsq [-n] [-f jsfile1.js]* [-q jsonquery] [-d delim] "+
"[-b script] \\\n"+
- " [-a script] [script]");
+ " [-a script] [-v NAME=VALUE] [script]");
quit(1);
};
@@ -1004,6 +1004,13 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
if (argv.length < 1) usage();
afters.push(makeFilter(argv.shift()));
break;
+ case "-v":
+ if (argv.length < 1) usage();
+ var tmp = argv.shift();
+ var key = tmp.replace(/=.*$/, "");
+ var val = tmp.replace(/^[^=]+=/, "");
+ window[key] = val;
+ break;
default:
fun = arg;
}
Please sign in to comment.
Something went wrong with that request. Please try again.