diff --git a/.gitignore b/.gitignore index c0fcad8..8f29ed4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +lib node_modules npm-debug.log *.DS_Store diff --git a/README.md b/README.md index c747c2a..70f5888 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,15 @@ It can also handle gzipped files. If the extension is .gz, it will decompress th jwalk somefile.json.gz ``` +## Running from source +There is a makefile that tests against the package.json file located within the repository. Simply type + +``` +make +``` + +to compile the source files into javascript and execute jwalk against package.json + ## Possible Commands Given the following json file diff --git a/makefile b/makefile new file mode 100644 index 0000000..3798cb1 --- /dev/null +++ b/makefile @@ -0,0 +1,12 @@ +START=node lib/index.js + +run: build + $(START) package.json + +build: clean + coffee -o lib . + +clean: + rm -rf lib + +.PHONY: clean build run diff --git a/src/commands/Command.coffee b/src/commands/Command.coffee index e95df19..593c48f 100644 --- a/src/commands/Command.coffee +++ b/src/commands/Command.coffee @@ -14,4 +14,10 @@ class Command inspect: (obj, depth) -> console.log util.inspect(obj, false, depth, true) -module.exports = Command \ No newline at end of file + inspectProperty: (obj, prop) -> + if obj[prop] != undefined + console.log util.inspect(obj[prop], false, 1, true) + else + console.log "Property does not exist" + +module.exports = Command diff --git a/src/commands/Inspect.coffee b/src/commands/Inspect.coffee index 91731ff..26493f1 100644 --- a/src/commands/Inspect.coffee +++ b/src/commands/Inspect.coffee @@ -6,8 +6,15 @@ class Inspect extends Command 'examines a single node' run: (context, args, callback) -> - depth = if args.length > 0 then Number(args[0]) else 1 - @inspect context.pointer, depth + depth = 1 + if args.length > 0 and isFinite args[0] + depth = Number args[0] + @inspect context.pointer, depth + else if args.length > 0 + @inspectProperty context.pointer, args[0] + else + depth = 1 + @inspect context.pointer, depth callback() -module.exports = Inspect \ No newline at end of file +module.exports = Inspect