-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathset.ts
49 lines (39 loc) · 1.53 KB
/
set.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
49
import {Command, flags as Flags} from '@heroku-cli/command'
import {Args} from '@oclif/core'
import {BuildpackCommand} from '../../lib/buildpacks/buildpacks'
export default class Set extends Command {
static description: 'set new app buildpack, overwriting 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 = {
buildpack: Args.string({
required: true,
description: 'namespace/name of the buildpack',
}),
}
async run() {
const {args, flags} = await this.parse(Set)
if (flags.index && flags.index < 0) {
this.error('Invalid index. Must be greater than 0.')
}
const buildpackCommand = new BuildpackCommand(this.heroku)
const buildpacks = await buildpackCommand.fetch(flags.app)
await buildpackCommand.validateUrlNotSet(buildpacks, args.buildpack)
let spliceIndex: number
if (flags.index === undefined) {
spliceIndex = 0
} else {
// eslint-disable-next-line 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, 'set')
buildpackCommand.displayUpdate(flags.app, flags.remote || '', buildpackUpdates, 'set')
}
}