Skip to content

Commit 305cab5

Browse files
James TsaiJames Tsai
authored andcommitted
feat: add v1-api's notes and team-notes commands
1 parent d2cd612 commit 305cab5

8 files changed

Lines changed: 248 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"oclif": {
5555
"commands": "./lib/commands",
5656
"bin": "hackmd-cli",
57+
"topicSeparator": " ",
5758
"additionalHelpFlags": [
5859
"-h"
5960
],

src/commands/history.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import {Command, Flags, CliUx } from '@oclif/core'
22
import {APIClient} from '../api'
33

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

77
static examples = [
88
`$ hackmd-cli history
9-
ID Title Userpath Teampath
9+
ID Title User Path Team Path
1010
────────────────────── ──────────────────────────────── ────────────────────── ────────
1111
raUuSTetT5uQbqQfLnz9lA CLI test note gvfz2UB5THiKABQJQnLs6Q null
1212
BnC6gN0_TfStV2KKmPPXeg Welcome to your team's workspace null CLI-test `,
@@ -28,8 +28,12 @@ BnC6gN0_TfStV2KKmPPXeg Welcome to your team's workspace null C
2828
header: 'ID',
2929
},
3030
title: {},
31-
userPath: {},
32-
teamPath: {},
31+
userPath: {
32+
header:'User Path'
33+
},
34+
teamPath: {
35+
header: 'Team Path'
36+
},
3337
}, {
3438
printLine: this.log.bind(this),
3539
...flags

src/commands/notes.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {Command, Flags, CliUx } from '@oclif/core'
2+
import {APIClient} from '../api'
3+
4+
export default class Notes extends Command {
5+
static description = 'List user notes'
6+
7+
static examples = [
8+
`$ hackmd-cli notes
9+
ID Title User Path Team Path
10+
────────────────────── ──────────────────────────────── ────────────────────── ────────
11+
raUuSTetT5uQbqQfLnz9lA CLI test note gvfz2UB5THiKABQJQnLs6Q null `,
12+
]
13+
14+
static flags = {
15+
help: Flags.help({char: 'h'}),
16+
...CliUx.ux.table.flags(),
17+
}
18+
19+
async run() {
20+
const {flags} = await this.parse(Notes)
21+
22+
try {
23+
const notes = await APIClient.getNoteList()
24+
25+
CliUx.ux.table(notes, {
26+
id: {
27+
header: 'ID',
28+
},
29+
title: {},
30+
userPath: {
31+
header:'User Path'
32+
},
33+
teamPath: {
34+
header: 'Team Path'
35+
},
36+
}, {
37+
printLine: this.log.bind(this),
38+
...flags
39+
})
40+
} catch (e) {
41+
this.log('Fetch user notes failed')
42+
this.error(e)
43+
}
44+
}
45+
}

src/commands/team-notes/create.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import {Command, Flags, CliUx} from '@oclif/core'
2+
3+
import {APIClient} from '../../api'
4+
5+
export default class Create extends Command {
6+
static description = 'Create a team note'
7+
8+
static examples = [
9+
`team-notes:create --teamPath=CLI-test --content='# A new note created' --readPermission=owner --writePermission=owner --commentPermission=disabled
10+
ID Title User Path Team Path
11+
────────────────────── ──────────────────────────────── ────────────────────── ────────
12+
raUuSTetT5uQbqQfLnz9lA CLI test note gvfz2UB5THiKABQJQnLs6Q null `
13+
]
14+
15+
static flags = {
16+
help: Flags.help({char: 'h'}),
17+
teamPath: Flags.string(),
18+
title: Flags.string(),
19+
content: Flags.string(),
20+
readPermission: Flags.string(),
21+
writePermission: Flags.string(),
22+
commentPermission: Flags.string(),
23+
...CliUx.ux.table.flags(),
24+
}
25+
26+
async run() {
27+
const {flags} = await this.parse(Create)
28+
const {teamPath, title, content, readPermission, writePermission, commentPermission} = flags
29+
const options = {title, content, readPermission, writePermission, commentPermission}
30+
31+
if(!teamPath) {
32+
this.error('Flag teamPath could not be empty')
33+
}
34+
35+
try {
36+
// TODO: create note options typing
37+
const note = await APIClient.createTeamNote(teamPath, options as any)
38+
39+
CliUx.ux.table([note], {
40+
id: {
41+
header: 'ID',
42+
},
43+
title: {},
44+
userPath: {
45+
header: 'User path'
46+
},
47+
teamPath:{
48+
header: 'Team path'
49+
}
50+
}, {
51+
printLine: this.log.bind(this),
52+
...flags
53+
})
54+
} catch (e) {
55+
this.log('Update team note content failed')
56+
this.error(e)
57+
}
58+
}
59+
}
60+

src/commands/team-notes/delete.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {Command, Flags} from '@oclif/core'
2+
3+
import {APIClient} from '../../api'
4+
5+
export default class Delete extends Command {
6+
static description = 'Delete a team note'
7+
8+
static examples = [
9+
`$ hackmd-cli team-notes delete --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA`
10+
]
11+
12+
static flags = {
13+
help: Flags.help({char: 'h'}),
14+
teamPath: Flags.string(),
15+
noteId: Flags.string(),
16+
}
17+
18+
async run() {
19+
const {flags} = await this.parse(Delete)
20+
const {teamPath, noteId} = flags
21+
22+
if(!teamPath) {
23+
this.error('Flag teamPath could not be empty')
24+
}
25+
26+
if(!noteId) {
27+
this.error('Flag noteId could not be empty')
28+
}
29+
30+
try {
31+
await APIClient.deleteTeamNote(teamPath, noteId)
32+
} catch (e) {
33+
this.log('Delete team note failed')
34+
this.error(e)
35+
}
36+
}
37+
}
38+

src/commands/team-notes/index.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {Command, Flags, CliUx } from '@oclif/core'
2+
3+
import {APIClient} from '../../api'
4+
5+
export default class IndexCommand extends Command {
6+
static description = 'HackMD team-notes commands'
7+
8+
static examples = [
9+
`$ hackmd-cli team-notes --teamPath=CLI-test
10+
ID Title User path Team path
11+
────────────────────── ──────────────────────────────── ──────── ────────
12+
WNkLM6gkS0Cg2cQ8rv7bYA a team note null CLI-test
13+
BnC6gN0_TfStV2KKmPPXeg Welcome to your team's workspace null CLI-test`,
14+
]
15+
16+
static flags = {
17+
help: Flags.help({char: 'h'}),
18+
teamPath: Flags.string(),
19+
...CliUx.ux.table.flags(),
20+
}
21+
22+
async run() {
23+
const {flags} = await this.parse(IndexCommand)
24+
25+
if(!flags.teamPath) {
26+
this.error('Flag teamPath could not be empty')
27+
}
28+
29+
try {
30+
const notes = await APIClient.getTeamNotes(flags.teamPath)
31+
32+
CliUx.ux.table(notes, {
33+
id: {
34+
header: 'ID',
35+
},
36+
title: {},
37+
userPath: {
38+
header: 'User path'
39+
},
40+
teamPath:{
41+
header: 'Team path'
42+
}
43+
}, {
44+
printLine: this.log.bind(this),
45+
...flags
46+
})
47+
} catch (e) {
48+
this.log('Fetch team note list failed')
49+
this.error(e)
50+
}
51+
}
52+
}
53+

src/commands/team-notes/update.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {Command, Flags} from '@oclif/core'
2+
3+
import {APIClient} from '../../api'
4+
5+
export default class Update extends Command {
6+
static description = 'Update a team note'
7+
8+
static examples = [
9+
`$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title'`
10+
]
11+
12+
static flags = {
13+
help: Flags.help({char: 'h'}),
14+
teamPath: Flags.string(),
15+
noteId: Flags.string(),
16+
content: Flags.string()
17+
}
18+
19+
async run() {
20+
const {flags} = await this.parse(Update)
21+
const {teamPath, noteId, content} = flags
22+
23+
if(!teamPath) {
24+
this.error('Flag teamPath could not be empty')
25+
}
26+
27+
if(!noteId) {
28+
this.error('Flag noteId could not be empty')
29+
}
30+
31+
try {
32+
await APIClient.updateTeamNoteContent(teamPath, noteId, content)
33+
} catch (e) {
34+
this.log('Update team note content failed')
35+
this.error(e)
36+
}
37+
}
38+
}
39+

src/commands/whoami.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class Whoami extends Command {
77

88
static examples = [
99
`$ hackmd-cli whoami
10-
ID Name Email Userpath
10+
ID Name Email User path
1111
──────────────────────────────────── ────────────── ───── ──────────────────────
1212
82f7f3d9-4079-4c78-8a00-14094272ece9 Ming-Hsiu Tsai null gvfz2UB5THiKABQJQnLs6Q `,
1313
]
@@ -29,7 +29,9 @@ ID Name Email Userpath
2929
},
3030
name: {},
3131
email: {},
32-
userPath: {},
32+
userPath: {
33+
header: 'User Path'
34+
},
3335
}, {
3436
printLine: this.log.bind(this),
3537
...flags

0 commit comments

Comments
 (0)