Skip to content

Commit 841daa6

Browse files
authored
feat: add tags support to notes and team-notes commands (#97)
2 parents 5a8b2dd + 0f8b99b commit 841daa6

9 files changed

Lines changed: 120 additions & 46 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
package-lock.json
12
*-debug.log
23
*-error.log
34
/.nyc_output

README.md

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ Create a note
455455
```
456456
USAGE
457457
$ hackmd-cli notes create [--commentPermission <value>] [--content <value>] [-e] [-h] [--parentFolderId <value>]
458-
[--readPermission <value>] [--title <value>] [--writePermission <value>] [--columns <value> | -x] [--sort <value>]
459-
[--filter <value>] [--output csv|json|yaml | | [--csv | --no-truncate]] [--no-header | ]
458+
[--readPermission <value>] [--tags <value>] [--title <value>] [--writePermission <value>] [--columns <value> | -x]
459+
[--sort <value>] [--filter <value>] [--output csv|json|yaml | | [--csv | --no-truncate]] [--no-header | ]
460460
461461
FLAGS
462462
-e, --editor create note with $EDITOR
@@ -474,6 +474,7 @@ FLAGS
474474
--parentFolderId=<value> parent folder id
475475
--readPermission=<value> set note permission: owner, signed_in, guest
476476
--sort=<value> property to sort by (prepend '-' for descending)
477+
--tags=<value> set note tags, comma-separated (e.g. tag1,tag2)
477478
--title=<value> new note title
478479
--writePermission=<value> set note permission: owner, signed_in, guest
479480
@@ -517,25 +518,34 @@ EXAMPLES
517518

518519
## `hackmd-cli notes update`
519520

520-
Update note content
521+
Update note
521522

522523
```
523524
USAGE
524-
$ hackmd-cli notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>]
525+
$ hackmd-cli notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>] [--permalink <value>]
526+
[--readPermission <value>] [--tags <value>] [--writePermission <value>]
525527
526528
FLAGS
527-
-h, --help Show CLI help.
528-
--content=<value> new note content
529-
--noteId=<value> HackMD note id
530-
--parentFolderId=<value> parent folder id
529+
-h, --help Show CLI help.
530+
--content=<value> new note content
531+
--noteId=<value> HackMD note id
532+
--parentFolderId=<value> parent folder id
533+
--permalink=<value> note permalink
534+
--readPermission=<value> set note permission: owner, signed_in, guest
535+
--tags=<value> set note tags, comma-separated (e.g. tag1,tag2)
536+
--writePermission=<value> set note permission: owner, signed_in, guest
531537
532538
DESCRIPTION
533-
Update note content
539+
Update note
534540
535541
EXAMPLES
536542
$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title'
537543
538544
$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title'
545+
546+
$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --readPermission=owner --writePermission=owner
547+
548+
$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --tags=tag1,tag2
539549
```
540550

541551
## `hackmd-cli team-folders`
@@ -721,8 +731,9 @@ Create a team note
721731
```
722732
USAGE
723733
$ hackmd-cli team-notes create [--commentPermission <value>] [--content <value>] [-e] [-h] [--parentFolderId <value>]
724-
[--readPermission <value>] [--teamPath <value>] [--title <value>] [--writePermission <value>] [--columns <value> |
725-
-x] [--sort <value>] [--filter <value>] [--output csv|json|yaml | | [--csv | --no-truncate]] [--no-header | ]
734+
[--readPermission <value>] [--tags <value>] [--teamPath <value>] [--title <value>] [--writePermission <value>]
735+
[--columns <value> | -x] [--sort <value>] [--filter <value>] [--output csv|json|yaml | | [--csv | --no-truncate]]
736+
[--no-header | ]
726737
727738
FLAGS
728739
-e, --editor create note with $EDITOR
@@ -740,6 +751,7 @@ FLAGS
740751
--parentFolderId=<value> parent folder id
741752
--readPermission=<value> set note permission: owner, signed_in, guest
742753
--sort=<value> property to sort by (prepend '-' for descending)
754+
--tags=<value> set note tags, comma-separated (e.g. tag1,tag2)
743755
--teamPath=<value> HackMD team path
744756
--title=<value> new note title
745757
--writePermission=<value> set note permission: owner, signed_in, guest
@@ -785,27 +797,35 @@ EXAMPLES
785797

786798
## `hackmd-cli team-notes update`
787799

788-
Update team note content
800+
Update team note
789801

790802
```
791803
USAGE
792-
$ hackmd-cli team-notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>] [--teamPath
793-
<value>]
804+
$ hackmd-cli team-notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>]
805+
[--permalink <value>] [--readPermission <value>] [--tags <value>] [--teamPath <value>] [--writePermission <value>]
794806
795807
FLAGS
796-
-h, --help Show CLI help.
797-
--content=<value> new note content
798-
--noteId=<value> HackMD note id
799-
--parentFolderId=<value> parent folder id
800-
--teamPath=<value> HackMD team path
808+
-h, --help Show CLI help.
809+
--content=<value> new note content
810+
--noteId=<value> HackMD note id
811+
--parentFolderId=<value> parent folder id
812+
--permalink=<value> note permalink
813+
--readPermission=<value> set note permission: owner, signed_in, guest
814+
--tags=<value> set note tags, comma-separated (e.g. tag1,tag2)
815+
--teamPath=<value> HackMD team path
816+
--writePermission=<value> set note permission: owner, signed_in, guest
801817
802818
DESCRIPTION
803-
Update team note content
819+
Update team note
804820
805821
EXAMPLES
806822
$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title'
807823
808824
$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title'
825+
826+
$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --readPermission=owner --writePermission=owner
827+
828+
$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --tags=tag1,tag2
809829
```
810830

811831
## `hackmd-cli teams`

src/commands/notes/create.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
editor,
1414
noteContent,
1515
notePermission,
16+
noteTags,
1617
noteTitle,
1718
parentFolderId,
1819
} from '../../flags'
@@ -47,6 +48,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
4748
help: Flags.help({char: 'h'}),
4849
parentFolderId,
4950
readPermission: notePermission,
51+
tags: noteTags,
5052
title: noteTitle,
5153
writePermission: notePermission,
5254
...ux.table.flags(),
@@ -56,7 +58,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
5658
const {flags} = await this.parse(CreateCommand)
5759
const pipeString = safeStdinRead()
5860

59-
const options: CreateNoteOptions = {
61+
const options: CreateNoteOptions & {tags?: string[]} = {
6062
commentPermission: flags.commentPermission as CommentPermissionType,
6163
content: pipeString || flags.content,
6264
parentFolderId: flags.parentFolderId,
@@ -65,6 +67,10 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
6567
writePermission: flags.writePermission as NotePermissionRole,
6668
}
6769

70+
if (flags.tags !== undefined) {
71+
options.tags = flags.tags.split(',').map((t: string) => t.trim()).filter(Boolean)
72+
}
73+
6874
if (flags.editor) {
6975
try {
7076
const mdFile = temporaryMD()
@@ -78,14 +84,17 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
7884

7985
try {
8086
const APIClient = await this.getAPIClient()
81-
const note = await APIClient.createNote(options)
87+
const note = await APIClient.createNote(options as CreateNoteOptions)
8288

8389
ux.table(
8490
[note],
8591
{
8692
id: {
8793
header: 'ID',
8894
},
95+
tags: {
96+
get: row => (row.tags ?? []).join(', '),
97+
},
8998
teamPath: {
9099
header: 'Team path',
91100
},

src/commands/notes/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ raUuSTetT5uQbqQfLnz9lA CLI test note gvfz2UB5THiKABQJQnLs6Q n
2828
id: {
2929
header: 'ID',
3030
},
31+
tags: {
32+
get: row => (row.tags ?? []).join(', '),
33+
},
3134
teamPath: {
3235
header: 'Team Path',
3336
},

src/commands/notes/update.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,53 @@
1-
import type {UpdateNoteOptions} from '@hackmd/api'
1+
import type {NotePermissionRole, UpdateNoteOptions} from '@hackmd/api'
22

33
import {Flags} from '@oclif/core'
44

55
import HackMDCommand from '../../command'
6-
import {noteContent, noteId, parentFolderId} from '../../flags'
6+
import {
7+
noteContent, noteId, notePermission, noteTags, parentFolderId, permalink,
8+
} from '../../flags'
79

810
export default class Update extends HackMDCommand {
9-
static description = 'Update note content'
11+
static description = 'Update note'
1012
static examples = [
1113
"$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title'",
1214
"$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title'",
15+
'$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --readPermission=owner --writePermission=owner',
16+
'$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --tags=tag1,tag2',
1317
]
1418
static flags = {
1519
content: noteContent,
1620
help: Flags.help({char: 'h'}),
1721
noteId,
1822
parentFolderId,
23+
permalink,
24+
readPermission: notePermission,
25+
tags: noteTags,
26+
writePermission: notePermission,
1927
}
2028

2129
async run() {
2230
const {flags} = await this.parse(Update)
23-
const {content, noteId, parentFolderId} = flags
31+
const {content, noteId, parentFolderId, permalink, readPermission, tags, writePermission} = flags
2432

2533
if (!noteId) {
2634
this.error('Flag noteId could not be empty')
2735
}
2836

29-
const payload: UpdateNoteOptions = {
30-
content,
31-
parentFolderId,
32-
}
37+
const payload: UpdateNoteOptions & {tags?: string[]} = {}
38+
39+
if (content !== undefined) payload.content = content
40+
if (parentFolderId !== undefined) payload.parentFolderId = parentFolderId
41+
if (readPermission !== undefined) payload.readPermission = readPermission as NotePermissionRole
42+
if (writePermission !== undefined) payload.writePermission = writePermission as NotePermissionRole
43+
if (permalink !== undefined) payload.permalink = permalink
44+
if (tags !== undefined) payload.tags = tags.split(',').map((t: string) => t.trim()).filter(Boolean)
3345

3446
try {
3547
const APIClient = await this.getAPIClient()
36-
await APIClient.updateNote(noteId, payload)
48+
await APIClient.updateNote(noteId, payload as UpdateNoteOptions)
3749
} catch (error) {
38-
this.log('Update note content failed')
50+
this.log('Update note failed')
3951
this.error(error as Error)
4052
}
4153
}

src/commands/team-notes/create.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import fs from 'node:fs'
55

66
import HackMDCommand from '../../command'
77
import {
8-
commentPermission, editor, noteContent, notePermission, noteTitle, parentFolderId, teamPath,
8+
commentPermission, editor, noteContent, notePermission, noteTags, noteTitle, parentFolderId, teamPath,
99
} from '../../flags'
1010
import {openEditor} from '../../open-editor'
1111
import {safeStdinRead, temporaryMD} from '../../utils'
@@ -38,6 +38,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
3838
help: Flags.help({char: 'h'}),
3939
parentFolderId,
4040
readPermission: notePermission,
41+
tags: noteTags,
4142
teamPath,
4243
title: noteTitle,
4344
writePermission: notePermission,
@@ -48,8 +49,8 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
4849
const {flags} = await this.parse(Create)
4950
const pipeString = safeStdinRead()
5051

51-
const {commentPermission, content, parentFolderId, readPermission, teamPath, title, writePermission} = flags
52-
const options: CreateNoteOptions = {
52+
const {commentPermission, content, parentFolderId, readPermission, tags, teamPath, title, writePermission} = flags
53+
const options: CreateNoteOptions & {tags?: string[]} = {
5354
commentPermission: commentPermission as CommentPermissionType,
5455
content: pipeString || content,
5556
parentFolderId,
@@ -58,6 +59,10 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
5859
writePermission: writePermission as NotePermissionRole,
5960
}
6061

62+
if (tags !== undefined) {
63+
options.tags = tags.split(',').map((t: string) => t.trim()).filter(Boolean)
64+
}
65+
6166
if (!teamPath) {
6267
this.error('Flag teamPath could not be empty')
6368
}
@@ -75,12 +80,15 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
7580

7681
try {
7782
const APIClient = await this.getAPIClient()
78-
const note = await APIClient.createTeamNote(teamPath, options)
83+
const note = await APIClient.createTeamNote(teamPath, options as CreateNoteOptions)
7984

8085
ux.table([note], {
8186
id: {
8287
header: 'ID',
8388
},
89+
tags: {
90+
get: row => (row.tags ?? []).join(', '),
91+
},
8492
teamPath: {
8593
header: 'Team path',
8694
},

src/commands/team-notes/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ BnC6gN0_TfStV2KKmPPXeg Welcome to your team's workspace null CLI-test`,
3333
id: {
3434
header: 'ID',
3535
},
36+
tags: {
37+
get: row => (row.tags ?? []).join(', '),
38+
},
3639
teamPath: {
3740
header: 'Team path',
3841
},

src/commands/team-notes/update.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1-
import type {UpdateNoteOptions} from '@hackmd/api'
1+
import type {NotePermissionRole, UpdateNoteOptions} from '@hackmd/api'
22

33
import {Flags} from '@oclif/core'
44

55
import HackMDCommand from '../../command'
66
import {
7-
noteContent, noteId, parentFolderId, teamPath,
7+
noteContent, noteId, notePermission, noteTags, parentFolderId, permalink, teamPath,
88
} from '../../flags'
99

1010
export default class Update extends HackMDCommand {
11-
static description = 'Update team note content'
11+
static description = 'Update team note'
1212
static examples = [
1313
"$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title'",
1414
"$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title'",
15+
'$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --readPermission=owner --writePermission=owner',
16+
'$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --tags=tag1,tag2',
1517
]
1618
static flags = {
1719
content: noteContent,
1820
help: Flags.help({char: 'h'}),
1921
noteId,
2022
parentFolderId,
23+
permalink,
24+
readPermission: notePermission,
25+
tags: noteTags,
2126
teamPath,
27+
writePermission: notePermission,
2228
}
2329

2430
async run() {
2531
const {flags} = await this.parse(Update)
26-
const {content, noteId, parentFolderId, teamPath} = flags
32+
const {content, noteId, parentFolderId, permalink, readPermission, tags, teamPath, writePermission} = flags
2733

2834
if (!teamPath) {
2935
this.error('Flag teamPath could not be empty')
@@ -33,16 +39,20 @@ export default class Update extends HackMDCommand {
3339
this.error('Flag noteId could not be empty')
3440
}
3541

36-
const payload: UpdateNoteOptions = {
37-
content,
38-
parentFolderId,
39-
}
42+
const payload: UpdateNoteOptions & {tags?: string[]} = {}
43+
44+
if (content !== undefined) payload.content = content
45+
if (parentFolderId !== undefined) payload.parentFolderId = parentFolderId
46+
if (readPermission !== undefined) payload.readPermission = readPermission as NotePermissionRole
47+
if (writePermission !== undefined) payload.writePermission = writePermission as NotePermissionRole
48+
if (permalink !== undefined) payload.permalink = permalink
49+
if (tags !== undefined) payload.tags = tags.split(',').map((t: string) => t.trim()).filter(Boolean)
4050

4151
try {
4252
const APIClient = await this.getAPIClient()
43-
await APIClient.updateTeamNote(teamPath, noteId, payload)
53+
await APIClient.updateTeamNote(teamPath, noteId, payload as UpdateNoteOptions)
4454
} catch (error) {
45-
this.log('Update team note content failed')
55+
this.log('Update team note failed')
4656
this.error(error as Error)
4757
}
4858
}

0 commit comments

Comments
 (0)