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

Add name based inspection #12

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lib
node_modules
npm-debug.log
*.DS_Store
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion src/commands/Command.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ class Command
inspect: (obj, depth) ->
console.log util.inspect(obj, false, depth, true)

module.exports = Command
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
13 changes: 10 additions & 3 deletions src/commands/Inspect.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
module.exports = Inspect