1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const command_1 = require("@heroku-cli/command");
|
4 | const buildpacks_1 = require("../../buildpacks");
|
5 | class Add extends command_1.Command {
|
6 | async run() {
|
7 | let { args, flags } = this.parse(Add);
|
8 | let buildpackCommand = new buildpacks_1.BuildpackCommand(this.heroku);
|
9 | if (flags.index !== undefined) {
|
10 | buildpackCommand.validateIndex(flags.index);
|
11 | }
|
12 | let buildpacks = await buildpackCommand.fetch(flags.app);
|
13 | await buildpackCommand.validateUrlNotSet(buildpacks, args.buildpack);
|
14 | let spliceIndex;
|
15 | if (flags.index === undefined) {
|
16 | spliceIndex = buildpacks.length;
|
17 | }
|
18 | else {
|
19 | let foundIndex = buildpackCommand.findIndex(buildpacks, flags.index);
|
20 | spliceIndex = (foundIndex === -1) ? buildpacks.length : foundIndex;
|
21 | }
|
22 | let buildpackUpdates = await buildpackCommand.mutate(flags.app, buildpacks, spliceIndex, args.buildpack, 'add');
|
23 | buildpackCommand.displayUpdate(flags.app, flags.remote || '', buildpackUpdates, 'added');
|
24 | }
|
25 | }
|
26 | Add.description = 'add new app buildpack, inserting into list of buildpacks if necessary';
|
27 | Add.flags = {
|
28 | app: command_1.flags.app({ required: true }),
|
29 | remote: command_1.flags.remote(),
|
30 | index: command_1.flags.integer({
|
31 | description: 'the 1-based index of the URL in the list of URLs',
|
32 | char: 'i'
|
33 | })
|
34 | };
|
35 | Add.args = [
|
36 | {
|
37 | name: 'buildpack',
|
38 | required: true,
|
39 | description: 'namespace/name of the buildpack'
|
40 | }
|
41 | ];
|
42 | exports.default = Add;
|