-
Notifications
You must be signed in to change notification settings - Fork 217
/
versions.ts
55 lines (50 loc) · 1.54 KB
/
versions.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
import {Command} from '@heroku-cli/command'
import {cli} from 'cli-ux'
import {Result} from 'true-myth'
import {BuildpackRegistry, RevisionBody} from '@heroku/buildpack-registry'
export default class Versions extends Command {
static description = 'list versions of a buildpack'
static args = [
{
name: 'buildpack',
required: true,
description: 'namespace/name of the buildpack'
}
]
async run() {
let {args} = this.parse(Versions)
let registry: BuildpackRegistry
let herokuAuth = this.heroku.auth || ''
if (herokuAuth === '') {
this.error('You need to be logged in to run this command.')
}
registry = new BuildpackRegistry()
Result.match({
Ok: _ => {},
Err: err => {
this.error(`Could not find the buildpack.\n${err}`)
},
}, BuildpackRegistry.isValidBuildpackSlug(args.buildpack))
let result = await registry.listVersions(args.buildpack)
Result.match({
Ok: versions => {
cli.table(versions.sort((a: RevisionBody, b: RevisionBody) => {
return a.release > b.release ? -1 : 1
}), {
columns: [
{key: 'release', label: 'Version'},
{key: 'created_at', label: 'Released At'},
{key: 'status', label: 'Status'}
]
})
},
Err: err => {
if (err.status === 404) {
this.error(`Could not find '${args.buildpack}'`)
} else {
this.error(`Problem fetching versions, ${err.status}: ${err.description}`)
}
}
}, result)
}
}