UNPKG

1.83 kBtext/coffeescriptView Raw
1_ = require 'lodash'
2colors = require 'colors'
3program = require 'commander'
4
5Config = require './src/config.coffee'
6packageJSON = require './package.json'
7
8DeployStateService = require './src/deploy-state-service'
9
10program
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
17class 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 @dieHelp new Error 'Missing repo' unless repo?
36 @dieHelp new Error 'Missing tag' unless tag?
37 @dieHelp new Error 'Missing cluster argument' unless cluster?
38 @dieHelp 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 dieHelp: (error) =>
52 program.outputHelp()
53 return @die error
54
55 die: (error) =>
56 return process.exit(0) unless error?
57 console.error error.stack
58 process.exit 1
59
60module.exports = Command