1 | _ = require 'lodash'
|
2 | colors = require 'colors'
|
3 | program = require 'commander'
|
4 |
|
5 | Config = require './src/config.coffee'
|
6 | packageJSON = require './package.json'
|
7 |
|
8 | DeployStateService = require './src/deploy-state-service'
|
9 |
|
10 | program
|
11 | .version packageJSON.version
|
12 | .usage '[options] <project-name> <tag>'
|
13 | .option '-o, --owner <octoblu>', 'Project owner'
|
14 | .option '-c, --cluster <major>', 'The cluster to the set the state on. i.e. `minor`, `major`, or `hpe`'
|
15 | .option '-p, --passing <true>', 'A boolean to indicate whether the build is passing or failing.'
|
16 |
|
17 | class Command
|
18 | constructor: ->
|
19 | process.on 'uncaughtException', @die
|
20 | @config = new Config()
|
21 | {@repo, @owner, @tag, @cluster, @passing } = @parseOptions()
|
22 | @deployStateService = new DeployStateService { config: @config.get() }
|
23 |
|
24 | parseOptions: =>
|
25 | program.parse process.argv
|
26 | repo = program.args[0]
|
27 | repo ?= @config.getPackageName()
|
28 |
|
29 | tag = program.args[1]
|
30 | tag ?= @config.getPackageVersion()
|
31 |
|
32 | { owner, cluster } = program
|
33 | owner ?= 'octoblu'
|
34 |
|
35 | throw new Error 'Missing repo argument' unless repo?
|
36 | throw new Error 'Missing tag argument' unless tag?
|
37 | throw new Error 'Missing cluster argument' unless cluster?
|
38 | throw new Error 'Missing passing argument' unless program.passing?
|
39 |
|
40 | passing = false
|
41 | passing = true if program.passing == 'true'
|
42 |
|
43 | return { repo, owner, tag, cluster, passing }
|
44 |
|
45 | run: =>
|
46 | options = { @repo, @owner, @tag, state: @cluster, @passing, type: 'cluster' }
|
47 | @deployStateService.setState options, (error, deployment) =>
|
48 | return @die error if error?
|
49 | process.exit 0
|
50 |
|
51 | die: (error) =>
|
52 | return process.exit(0) unless error?
|
53 | console.error 'ERROR'
|
54 | console.error error.stack
|
55 | process.exit 1
|
56 |
|
57 | module.exports = Command
|