Permalink
Browse files

() add version number option.

  • Loading branch information...
1 parent b728ef6 commit 9f6411a4e553a19e3c66fe2aba36ed487fc7c1c9 @zpoley committed Feb 26, 2011
Showing with 23 additions and 1 deletion.
  1. +2 −0 README.md
  2. +19 −1 lib/jsonCommand.js
  3. +2 −0 man/json.1
View
@@ -52,6 +52,8 @@ please note that the last two examples require you to enter your username and pa
-h print help info and exit
+ -v (-V | --version) print version number and exit
+
-u print ugly json output, each object on a single line
-d print debugging output including exception messages
View
@@ -38,6 +38,7 @@ JSON.Command.prototype.printhelp = function() {
sys.puts("");
sys.puts("options:\n");
sys.puts(" -h print this help info and exit\n");
+ sys.puts(" -v (-V | --version) print version number and exit\n");
sys.puts(" -u print ugly json output, each object on a single line\n");
sys.puts(" -d print debugging output including exception messages\n");
sys.puts(" -o object.path specify the path to an array to be iterated on\n");
@@ -50,6 +51,7 @@ JSON.Command.prototype.printhelp = function() {
sys.puts(" -i use node's sys.inspect instead of JSON.stringify\n");
sys.puts(" -H print headers, if they are supplied.");
sys.puts(" Useful for output from curl -i.\n");
+
sys.puts("examples:\n");
sys.puts(" curl http://search.twitter.com/search.json?q=node.js 2> /dev/null |");
sys.puts(" json -o results\n");
@@ -58,10 +60,21 @@ JSON.Command.prototype.printhelp = function() {
sys.puts(" curl http://search.twitter.com/search.json?q=node.js 2> /dev/null |");
sys.puts(" json -o results -C from_user from_user_id text\n");
sys.puts("more help:\n");
- sys.puts(" use \"man json-command\" or visit http://github.com/zpoley/json-command\n");
+ sys.puts(" use \"man json\" or visit http://github.com/zpoley/json-command\n");
process.exit();
};
+JSON.Command.prototype.printversion = function() {
+ var npm = require("npm");
+ npm.load([], function(er) {
+ sys.print("json command line toolkit\n version: ");
+ npm.commands.info([ "json", "version" ], function(er, data) {
+ process.exit();
+ });
+ });
+};
+
+
JSON.Command.prototype.stringify = function(obj) {
return( this.inspectOutput ? sys.inspect(obj, false, Infinity, true)
: this.uglyOutput ? JSON.stringify(obj)
@@ -101,6 +114,11 @@ JSON.Command.prototype.processArgs = function processArgs(args) {
case "-h": // display help and exit
this.printhelp();
break;
+ case "-v": // display version and exit
+ case "-V":
+ case "--version":
+ this.printversion();
+ break;
case "-f": // file
this.fileNames.push(a.shift());
break;
View
@@ -21,6 +21,8 @@ inspecting and transforming the parsed json objects.
.\"file or glob to process as input.
.IP -h
print help info and exit.
+.IP -v (-V | --version)
+print version number and exit.
.IP -u
print ugly json output, each object on a single line.
.IP -d

0 comments on commit 9f6411a

Please sign in to comment.