Skip to content

Commit dc22c5f

Browse files
committed
Add list command
1 parent 16aad49 commit dc22c5f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/commands/list.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {Command, flags} from '@oclif/command'
2+
import cli from 'cli-ux'
3+
4+
import {APIClient} from '../api'
5+
6+
export default class History extends Command {
7+
static description = 'List notes'
8+
9+
static examples = [
10+
`$ hackmd-cli list
11+
12+
ID Name
13+
A58r8ehYTlySO94oiC_MUA Note1
14+
EeNHDGocSTi70ytMMGQaaQ Note2`,
15+
]
16+
17+
static flags = {
18+
help: flags.help({char: 'h'}),
19+
team: flags.string({
20+
char: 't',
21+
description: 'team name',
22+
}),
23+
...cli.table.flags(),
24+
}
25+
26+
async run() {
27+
const {flags} = this.parse(History)
28+
29+
try {
30+
let notes
31+
if (flags.team) {
32+
notes = await APIClient.listTeamNotes(flags.team)
33+
} else {
34+
notes = await APIClient.listNotes()
35+
}
36+
37+
cli.table(notes, {
38+
id: {
39+
header: 'ID',
40+
},
41+
name: {
42+
get: row => (row as any).title
43+
}
44+
}, {
45+
printLine: this.log,
46+
...flags
47+
})
48+
} catch (e) {
49+
this.log('Fetch history failed')
50+
this.error(e as string)
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)