Skip to content

Commit d2cd612

Browse files
James TsaiJames Tsai
authored andcommitted
feat: add v1-api whomai cmd
1 parent c3482e1 commit d2cd612

2 files changed

Lines changed: 26 additions & 19 deletions

File tree

src/commands/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Command, Flags, CliUx } from '@oclif/core'
22
import {APIClient} from '../api'
33

44
export default class History extends Command {
5-
static description = 'List history'
5+
static description = 'List user browsing history'
66

77
static examples = [
88
`$ hackmd-cli history

src/commands/whoami.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
import {Command, flags} from '@oclif/command'
1+
import {Command, Flags, CliUx } from '@oclif/core'
22

33
import {APIClient} from '../api'
44

55
export default class Whoami extends Command {
6-
static description = 'Show logged in account info'
6+
static description = 'Show current user information'
77

88
static examples = [
99
`$ hackmd-cli whoami
10-
11-
You are logged in hackmd.io as {YOUR NAME} [user-id]
12-
`,
10+
ID Name Email Userpath
11+
──────────────────────────────────── ────────────── ───── ──────────────────────
12+
82f7f3d9-4079-4c78-8a00-14094272ece9 Ming-Hsiu Tsai null gvfz2UB5THiKABQJQnLs6Q `,
1313
]
1414

1515
static flags = {
16-
help: flags.help({char: 'h'}),
16+
help: Flags.help({char: 'h'}),
17+
...CliUx.ux.table.flags(),
1718
}
1819

1920
async run() {
20-
this.parse(Whoami)
21-
21+
const {flags} = await this.parse(Whoami)
22+
2223
try {
23-
const data = await APIClient.getMe()
24-
if (data.status === 'ok') {
25-
this.log(`You are logged in ${APIClient.domain} as ${data.name} [${data.id}]`)
26-
} else {
27-
this.log('You are not logged in yet.')
28-
}
29-
} catch (err) {
30-
this.log('Sorry, something went wrong!')
31-
32-
this.error(err)
24+
const user = await APIClient.getMe()
25+
26+
CliUx.ux.table([user], {
27+
id: {
28+
header: 'ID',
29+
},
30+
name: {},
31+
email: {},
32+
userPath: {},
33+
}, {
34+
printLine: this.log.bind(this),
35+
...flags
36+
})
37+
} catch (e) {
38+
this.log('Fetch user info failed')
39+
this.error(e)
3340
}
3441
}
3542
}

0 commit comments

Comments
 (0)