-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathversions.ts
59 lines (52 loc) · 1.55 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
56
57
58
59
import {Command} from '@heroku-cli/command'
import {Args, ux} from '@oclif/core'
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 = {
buildpack: Args.string({
required: true,
description: 'namespace/name of the buildpack',
}),
}
async run() {
const {args} = await this.parse(Versions)
const herokuAuth = this.heroku.auth || ''
if (herokuAuth === '') {
this.error('You need to be logged in to run this command.')
}
const registry = new BuildpackRegistry()
Result.match({
Ok: () => {},
Err: err => {
this.error(`Could not find the buildpack.\n${err}`)
},
}, BuildpackRegistry.isValidBuildpackSlug(args.buildpack))
const result = await registry.listVersions(args.buildpack)
Result.match({
Ok: versions => {
ux.table(versions.sort((a: RevisionBody, b: RevisionBody) => {
return a.release > b.release ? -1 : 1
}), {
release: {
header: 'Version',
},
created_at: {
header: 'Released At',
},
status: {
header: '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)
}
}