-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathremove.ts
61 lines (50 loc) · 2.06 KB
/
remove.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
50
51
52
53
54
55
56
57
58
59
60
61
import {Command, flags as Flags} from '@heroku-cli/command'
import {Args, ux} from '@oclif/core'
import {BuildpackCommand} from '../../lib/buildpacks/buildpacks'
export default class Remove extends Command {
static description = 'remove a buildpack set on the app'
static flags = {
app: Flags.app({required: true}),
remote: Flags.remote(),
index: Flags.integer({
description: 'the 1-based index of the URL to remove from the list of URLs',
char: 'i',
}),
}
static args = {
buildpack: Args.string({
description: 'namespace/name of the buildpack',
}),
}
async run() {
const {args, flags} = await this.parse(Remove)
const buildpackCommand = new BuildpackCommand(this.heroku)
if (flags.index && args.buildpack) {
ux.error('Please choose either index or Buildpack, but not both.', {exit: 1})
}
if (!flags.index && !args.buildpack) {
ux.error('Usage: heroku buildpacks:remove [BUILDPACK_URL]. Must specify a buildpack to remove, either by index or URL.')
}
const buildpacks = await buildpackCommand.fetch(flags.app)
if (buildpacks.length === 0) {
ux.error(`No buildpacks were found. Next release on ${flags.app} will detect buildpack normally.`, {exit: 1})
}
let spliceIndex: number
if (flags.index) {
buildpackCommand.validateIndexInRange(buildpacks, flags.index)
// eslint-disable-next-line unicorn/no-array-method-this-argument
spliceIndex = await buildpackCommand.findIndex(buildpacks, flags.index)
} else {
spliceIndex = await buildpackCommand.findUrl(buildpacks, args.buildpack as string)
}
if (spliceIndex === -1) {
ux.error('Buildpack not found. Nothing was removed.', {exit: 1})
}
if (buildpacks.length === 1) {
await buildpackCommand.clear(flags.app, 'remove', 'removed')
} else {
const buildpackUpdates = await buildpackCommand.mutate(flags.app, buildpacks, spliceIndex, args.buildpack as string, 'remove')
buildpackCommand.displayUpdate(flags.app, flags.remote || '', buildpackUpdates, 'removed')
}
}
}