1
import {flags} from '@oclif/command'
2
import {CLIError, error} from '@oclif/errors'
3

4
import {AppCompletion, RemoteCompletion} from '../completions'
5
import {configRemote, getGitRemotes, IGitRemotes} from '../git'
6

7
class MultipleRemotesError extends CLIError {
8
  constructor(gitRemotes: IGitRemotes[]) {
9 0
    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 0
  ${gitRemotes.map(r => `${r.app} (${r.remote})`).join('\n')}
17

18
  https://devcenter.heroku.com/articles/multiple-environments`)
19
  }
20
}
21

22 0
export const app = flags.build({
23
  char: 'a',
24
  completion: AppCompletion,
25
  description: 'app to run command against',
26

27
  default: ({options, flags}) => {
28 0
    const envApp = process.env.HEROKU_APP
29 3
    if (envApp) return envApp
30 3
    let gitRemotes = getGitRemotes(flags.remote || configRemote())
31 3
    if (gitRemotes.length === 1) return gitRemotes[0].app
32 3
    if (flags.remote && gitRemotes.length === 0) {
33 0
      error(`remote ${flags.remote} not found in git remotes`)
34
    }
35 3
    if (gitRemotes.length > 1 && options.required) {
36 0
      throw new MultipleRemotesError(gitRemotes)
37
    }
38
  },
39
})
40

41 0
export const remote = flags.build({
42
  char: 'r',
43
  completion: RemoteCompletion,
44
  description: 'git remote of app to use',
45
})

Read our documentation on viewing source code .

Loading