Skip to content

Commit

Permalink
v5.9.0 search can take a file now
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Herres committed Jan 12, 2017
1 parent 762a030 commit 49f7588
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions command-search.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
_ = require 'lodash'
commander = require 'commander'
fs = require 'fs'
path = require 'path'
colors = require 'colors'

BaseCommand = require './base-command'

Expand All @@ -15,17 +18,30 @@ class SearchCommand extends BaseCommand
console.log JSON.stringify(data, null, 2)
process.exit 0

loadQueryFile: (filename) =>
try
return fs.readFileSync path.resolve(filename)
catch error
console.error colors.yellow error.message
console.error colors.red '\n Unable to open a valid query.json file'
commander.outputHelp()
process.exit 1


parseOptions: =>
commander
.option '-q, --query <query>', 'Meshblu device to get (defaults to uuid from meshblu.json)'
.option '-a, --as <uuid>', 'the uuid to send the message as (defaults to meshblu.json)'
.option '-f, --file <path/to/query.json>', 'query [JSON FILE]'
.usage '[options] <path/to/meshblu.json>'
.parse process.argv

@filename = _.first commander.args
@as = commander.as
@filename = _.first commander.args
@queryFileName = commander.file
@as = commander.as

{query} = commander
{query} = commander
query = @loadQueryFile(@queryFileName) if @queryFileName?

unless query?
commander.outputHelp()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meshblu-util",
"version": "5.8.0",
"version": "5.9.0",
"description": "Utils for managing Meshblu devices",
"main": "index.js",
"bin": {
Expand Down

0 comments on commit 49f7588

Please sign in to comment.