-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathregions.ts
40 lines (35 loc) · 1.33 KB
/
regions.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
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import {cli} from 'cli-ux'
import * as _ from 'lodash'
export default class Regions extends Command {
static topic = 'regions'
static description = 'list available regions for deployment'
static flags = {
json: flags.boolean({description: 'output in json format'}),
private: flags.boolean({description: 'show regions for private spaces'}),
common: flags.boolean({description: 'show regions for common runtime'}),
}
async run() {
const {flags} = this.parse(Regions)
let {body: regions} = await this.heroku.get<Heroku.Region[]>('/regions')
if (flags.private) {
regions = regions.filter((region: any) => region.private_capable)
} else if (flags.common) {
regions = regions.filter((region: any) => !region.private_capable)
}
regions = _.sortBy(regions, ['private_capable', 'name'])
if (flags.json) {
cli.styledJSON(regions)
} else {
cli.table(regions, {
columns: [
{key: 'name', label: 'ID', format: (n: any) => color.green(n)},
{key: 'description', label: 'Location'},
{key: 'private_capable', label: 'Runtime', format: (c: any) => c ? 'Private Spaces' : 'Common Runtime'},
],
})
}
}
}