-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathindex.ts
34 lines (27 loc) · 1001 Bytes
/
index.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
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import {OAuthSession} from '../../lib/sessions/sessions'
const {sortBy} = require('lodash')
export default class SessionsIndex extends Command {
static description = 'list your OAuth sessions'
static flags = {
json: flags.boolean({char: 'j', description: 'output in json format'}),
}
async run() {
const {flags} = await this.parse(SessionsIndex)
let {body: sessions} = await this.heroku.get<Array<OAuthSession>>('/oauth/sessions')
sessions = sortBy(sessions, 'description')
if (flags.json) {
ux.styledJSON(sessions)
} else if (sessions.length === 0) {
ux.log('No OAuth sessions.')
} else {
const printLine: typeof this.log = (...args) => this.log(...args)
ux.table(sessions, {
description: {get: (v: any) => color.green(v.description)},
id: {},
}, {'no-header': true, printLine})
}
}
}