Skip to content

Commit

Permalink
v5.11.0 add -r, --resolve to meshblu-util get for schema resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
iamruinous committed Feb 9, 2017
1 parent 53c654d commit 226eb43
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 40 deletions.
15 changes: 13 additions & 2 deletions command-get.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
_ = require 'lodash'
commander = require 'commander'
Resolver = require 'meshblu-json-schema-resolver'

BaseCommand = require './base-command'

Expand All @@ -8,17 +9,26 @@ class GetCommand extends BaseCommand
run: =>
@parseOptions()
meshbluHttp = @getMeshbluHttp()
meshbluConfig = @meshbluConfig.toJSON()
resolver = new Resolver { meshbluConfig }
@uuid ?= @getMeshbluConfig().uuid
meshbluHttp.device @uuid, {@as}, (error, data) =>
return @die error if error?

console.log JSON.stringify(data, null, 2)
process.exit 0
@printAndExit(data) unless @resolve
resolver.resolve data, (error, resolvedData) =>
@die error if error?
@printAndExit resolvedData

printAndExit: (data) =>
console.log JSON.stringify(data, null, 2)
process.exit 0

parseOptions: =>
commander
.option '-a, --as <uuid>', 'the uuid to send the message as (defaults to meshblu.json)'
.option '-u, --uuid <uuid>', 'Meshblu device to get (defaults to uuid from meshblu.json)'
.option '-r, --resolve', 'Use meshblu $ref resolver'
.usage '[options] <path/to/meshblu.json>'
.parse process.argv

Expand All @@ -27,5 +37,6 @@ class GetCommand extends BaseCommand
@as = commander.as
@events = (commander.events ? 'message,config').split ','
@types = (commander.types ? 'broadcast,received,sent').split ','
@resolve = commander.resolve

(new GetCommand()).run()
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meshblu-util",
"version": "5.10.0",
"version": "5.11.0",
"description": "Utils for managing Meshblu devices",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -59,6 +59,7 @@
"meshblu-config": "^6.0.0",
"meshblu-firehose-socket.io": "^2.0.0",
"meshblu-http": "^7.0.0",
"meshblu-json-schema-resolver": "^2.0.0",
"meshblu-websocket": "^4.0.0",
"meshblu-xmpp": "^1.4.4",
"open": "0.0.5"
Expand Down
Loading

0 comments on commit 226eb43

Please sign in to comment.