UNPKG

1.61 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.remote = exports.app = void 0;
4const core_1 = require("@oclif/core");
5const errors_1 = require("@oclif/core/lib/errors");
6const git_1 = require("../git");
7class MultipleRemotesError extends errors_1.CLIError {
8 constructor(gitRemotes) {
9 super(`Multiple apps in git remotes
10 Usage: --remote ${gitRemotes[1].remote}
11 or: --app ${gitRemotes[1].app}
12 Your local git repository has more than 1 app referenced in git remotes.
13 Because of this, we can't determine which app you want to run this command against.
14 Specify the app you want with --app or --remote.
15 Heroku remotes in repo:
16 ${gitRemotes.map(r => `${r.app} (${r.remote})`).join('\n')}
17
18 https://devcenter.heroku.com/articles/multiple-environments`);
19 }
20}
21exports.app = core_1.Flags.custom({
22 char: 'a',
23 description: 'app to run command against',
24 default: async ({ options, flags }) => {
25 const envApp = process.env.HEROKU_APP;
26 if (envApp)
27 return envApp;
28 const gitRemotes = (0, git_1.getGitRemotes)(flags.remote || (0, git_1.configRemote)());
29 if (gitRemotes.length === 1)
30 return gitRemotes[0].app;
31 if (flags.remote && gitRemotes.length === 0) {
32 (0, errors_1.error)(`remote ${flags.remote} not found in git remotes`);
33 }
34 if (gitRemotes.length > 1 && options.required) {
35 throw new MultipleRemotesError(gitRemotes);
36 }
37 },
38});
39exports.remote = core_1.Flags.custom({
40 char: 'r',
41 description: 'git remote of app to use',
42});