Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced the sys module, to be compatible with node 0.7.x #8

Merged
merged 1 commit into from Feb 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions bin/json.js
@@ -1,7 +1,6 @@
#!/usr/bin/env node

var sys = require("sys"),
jsonCommand = require("../lib/jsonCommand");
var jsonCommand = require("../lib/jsonCommand");

var args = process.argv.slice(0);
// shift off node and script name
Expand Down
74 changes: 37 additions & 37 deletions lib/jsonCommand.js
@@ -1,4 +1,4 @@
var sys = require("sys"),
var util = require("util"),
vm = require("vm");

/*
Expand Down Expand Up @@ -30,45 +30,45 @@ JSON.Command = function(args) {
};

JSON.Command.prototype.printhelp = function() {
sys.puts("usage: stdout_generator | json [options] [fields]");
sys.puts("");
sys.puts("json processes standard input and parses json objects. json currently handles a");
sys.puts("few different standard input formats and provides a number of options tailored");
sys.puts("toward inspecting and transforming the parsed json objects.");
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");
sys.puts(" new.key=old_key move old_key to new.key in output object\n");
sys.puts(" -a input object is an array, process each element separately\n");
sys.puts(" -c \"js conditional\" js conditional to be run in the context of each object");
sys.puts(" that determines whether an object is printed\n");
sys.puts(" -C print the output fields as tab delimited columns in");
sys.puts(" the order specified by fields\n");
sys.puts(" -e \"js expression\" execute arbitrary js in the context of each object.\n");
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");
sys.puts(" curl http://search.twitter.com/search.json?q=node.js 2> /dev/null |");
sys.puts(" json -o results new_id=id\n");
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\" or visit http://github.com/zpoley/json-command\n");
console.log("usage: stdout_generator | json [options] [fields]");
console.log("");
console.log("json processes standard input and parses json objects. json currently handles a");
console.log("few different standard input formats and provides a number of options tailored");
console.log("toward inspecting and transforming the parsed json objects.");
console.log("");
console.log("options:\n");
console.log(" -h print this help info and exit\n");
console.log(" -v (-V | --version) print version number and exit\n");
console.log(" -u print ugly json output, each object on a single line\n");
console.log(" -d print debugging output including exception messages\n");
console.log(" -o object.path specify the path to an array to be iterated on\n");
console.log(" new.key=old_key move old_key to new.key in output object\n");
console.log(" -a input object is an array, process each element separately\n");
console.log(" -c \"js conditional\" js conditional to be run in the context of each object");
console.log(" that determines whether an object is printed\n");
console.log(" -C print the output fields as tab delimited columns in");
console.log(" the order specified by fields\n");
console.log(" -e \"js expression\" execute arbitrary js in the context of each object.\n");
console.log(" -i use node's util.inspect instead of JSON.stringify\n");
console.log(" -H print headers, if they are supplied.");
console.log(" Useful for output from curl -i.\n");

console.log("examples:\n");
console.log(" curl http://search.twitter.com/search.json?q=node.js 2> /dev/null |");
console.log(" json -o results\n");
console.log(" curl http://search.twitter.com/search.json?q=node.js 2> /dev/null |");
console.log(" json -o results new_id=id\n");
console.log(" curl http://search.twitter.com/search.json?q=node.js 2> /dev/null |");
console.log(" json -o results -C from_user from_user_id text\n");
console.log("more help:\n");
console.log(" 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: ");
console.log("json command line toolkit\n version: ");
npm.commands.view([ "json", "version" ], function(er, data) {
process.exit();
});
Expand All @@ -77,13 +77,13 @@ JSON.Command.prototype.printversion = function() {


JSON.Command.prototype.stringify = function(obj) {
return( this.inspectOutput ? sys.inspect(obj, false, Infinity, true)
return( this.inspectOutput ? util.inspect(obj, false, Infinity, true)
: this.uglyOutput ? JSON.stringify(obj)
: JSON.stringify(obj, null, 2) );
};

JSON.Command.prototype.debug = function(msg) {
if (this.debugOn) { sys.puts(msg); }
if (this.debugOn) { console.log(msg); }
};

JSON.Command.prototype.printex = function(ex) {
Expand Down Expand Up @@ -144,7 +144,7 @@ JSON.Command.prototype.processArgs = function processArgs(args) {
case "-a": // array
this.inputIsArray = true;
break;
case "-i": // use sys.inspect
case "-i": // use util.inspect
this.inspectOutput = true;
break;
case "-H": // header passthrough
Expand Down