1 | _ = require 'lodash'
|
2 | dashdash = require 'dashdash'
|
3 | MeshbluConfig = require 'meshblu-config'
|
4 | Inquisitor = require './src/inquisitor'
|
5 |
|
6 | OPTIONS = [{
|
7 | names: ['uuid', 'u']
|
8 | type: 'string'
|
9 | help: 'The uuid to setup.'
|
10 | }]
|
11 |
|
12 | class Command
|
13 | constructor: (argv) ->
|
14 | process.on 'uncaughtException', @die
|
15 |
|
16 | parseOptions: (argv) =>
|
17 | parser = dashdash.createParser options: OPTIONS, allowUnknown: true, interspersed: false
|
18 | {@uuid} = parser.parse argv
|
19 |
|
20 | unless @uuid?
|
21 | console.log "Specify which device to set up with -u"
|
22 | process.exit 0
|
23 |
|
24 | run: =>
|
25 | @parseOptions()
|
26 | @inquisitor = new Inquisitor {meshbluConfig: new MeshbluConfig().toJSON(), @uuid}
|
27 | @inquisitor.setup (error) =>
|
28 | return @die error if error?
|
29 | console.log "Done."
|
30 |
|
31 | die: (error) =>
|
32 | return process.exit(0) unless error?
|
33 | console.error 'ERROR'
|
34 | console.error error.stack
|
35 | process.exit 1
|
36 |
|
37 | usage: (parser) =>
|
38 | return """
|
39 | usage: inquisitor -u <uuid>
|
40 | setup an inquisitor device
|
41 | options:
|
42 | #{parser.help({includeEnv: true})}
|
43 | """
|
44 |
|
45 | command = new Command(process.argv)
|
46 | command.run()
|