/
add.ts
48 lines (39 loc) · 1.52 KB
/
add.ts
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
import {Command, flags as Flags} from '@heroku-cli/command'
import {BuildpackCommand} from '../../buildpacks'
export default class Add extends Command {
static description = 'add new app buildpack, inserting into list of buildpacks if necessary'
static flags = {
app: Flags.app({required: true}),
remote: Flags.remote(),
index: Flags.integer({
description: 'the 1-based index of the URL in the list of URLs',
char: 'i',
}),
}
static args = [
{
name: 'buildpack',
required: true,
description: 'namespace/name of the buildpack',
},
]
async run() {
const {args, flags} = await this.parse(Add)
const buildpackCommand = new BuildpackCommand(this.heroku)
if (flags.index !== undefined) {
buildpackCommand.validateIndex(flags.index)
}
const buildpacks = await buildpackCommand.fetch(flags.app)
await buildpackCommand.validateUrlNotSet(buildpacks, args.buildpack)
let spliceIndex: number
if (flags.index === undefined) {
spliceIndex = buildpacks.length
} else {
// eslint-disable-next-line unicorn/no-array-callback-reference, unicorn/no-array-method-this-argument
const foundIndex = buildpackCommand.findIndex(buildpacks, flags.index)
spliceIndex = (foundIndex === -1) ? buildpacks.length : foundIndex
}
const buildpackUpdates = await buildpackCommand.mutate(flags.app, buildpacks, spliceIndex, args.buildpack, 'add')
buildpackCommand.displayUpdate(flags.app, flags.remote || '', buildpackUpdates, 'added')
}
}