-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathadd.ts
More file actions
67 lines (58 loc) · 2.05 KB
/
Copy pathadd.ts
File metadata and controls
67 lines (58 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {Command, flags} from '@heroku-cli/command'
import {StageCompletion} from '@heroku-cli/command/lib/completions.js'
import * as Heroku from '@heroku-cli/schema'
import * as color from '@heroku/heroku-cli-util/color'
import {Args, ux} from '@oclif/core'
import {createCoupling} from '../../lib/api.js'
import {lazyModuleLoader} from '../../lib/lazy-module-loader.js'
import disambiguate from '../../lib/pipelines/disambiguate.js'
import infer from '../../lib/pipelines/infer.js'
import {inferrableStageNames as stageNames} from '../../lib/pipelines/stages.js'
export default class PipelinesAdd extends Command {
static args = {
pipeline: Args.string({
description: 'name of pipeline',
required: true,
}),
}
static description = `add this app to a pipeline
The app and pipeline names must be specified.
The stage of the app will be guessed based on its name if not specified.`
static examples = [
color.command('heroku pipelines:add my-pipeline -a my-app -s production'),
]
static flags = {
app: flags.app({required: true}),
remote: flags.remote(),
stage: flags.string({
char: 's',
completion: StageCompletion,
description: 'stage of first app in pipeline',
}),
}
async run() {
const inquirer = await lazyModuleLoader.loadInquirer()
const {args, flags} = await this.parse(PipelinesAdd)
const {app} = flags
let stage
const guesses = infer(app)
const questions = []
const pipeline: Heroku.Pipeline = await disambiguate(this.heroku, args.pipeline)
if (flags.stage) {
stage = flags.stage
} else {
questions.push({
choices: stageNames,
default: guesses[1],
message: `Stage of ${app}`,
name: 'stage',
type: 'list',
})
}
const answers: any = await inquirer.prompt(questions)
if (answers.stage) stage = answers.stage
ux.action.start(`Adding ${color.app(app)} to ${color.pipeline(pipeline.name || '')} pipeline as ${stage}`)
await createCoupling(this.heroku, pipeline, app, stage)
ux.action.stop()
}
}