|
1 | | -import {Command, flags} from '@oclif/command' |
| 1 | +import {Command, Flags, CliUx } from '@oclif/core' |
2 | 2 |
|
3 | 3 | import {APIClient} from '../api' |
4 | 4 |
|
5 | 5 | export default class Whoami extends Command { |
6 | | - static description = 'Show logged in account info' |
| 6 | + static description = 'Show current user information' |
7 | 7 |
|
8 | 8 | static examples = [ |
9 | 9 | `$ 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 `, |
13 | 13 | ] |
14 | 14 |
|
15 | 15 | static flags = { |
16 | | - help: flags.help({char: 'h'}), |
| 16 | + help: Flags.help({char: 'h'}), |
| 17 | + ...CliUx.ux.table.flags(), |
17 | 18 | } |
18 | 19 |
|
19 | 20 | async run() { |
20 | | - this.parse(Whoami) |
21 | | - |
| 21 | + const {flags} = await this.parse(Whoami) |
| 22 | + |
22 | 23 | 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) |
33 | 40 | } |
34 | 41 | } |
35 | 42 | } |
0 commit comments