Skip to content

Commit 250dfe4

Browse files
authored
feat: support updating note titles (#115)
* feat: support updating note titles * docs: update skill for note title updates
1 parent 91821c0 commit 250dfe4

7 files changed

Lines changed: 38 additions & 10 deletions

File tree

‎README.md‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ Update note
523523
```
524524
USAGE
525525
$ hackmd-cli notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>] [--permalink
526-
<value>] [--readPermission <value>] [--tags <value>] [--writePermission <value>]
526+
<value>] [--readPermission <value>] [--tags <value>] [--title <value>] [--writePermission <value>]
527527
528528
FLAGS
529529
-h, --help Show CLI help.
@@ -533,12 +533,15 @@ FLAGS
533533
--permalink=<value> note permalink
534534
--readPermission=<value> set note permission: owner, signed_in, guest
535535
--tags=<value> set note tags, comma-separated (e.g. tag1,tag2)
536+
--title=<value> new note title
536537
--writePermission=<value> set note permission: owner, signed_in, guest
537538
538539
DESCRIPTION
539540
Update note
540541
541542
EXAMPLES
543+
$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --title='A new title'
544+
542545
$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title'
543546
544547
$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title'
@@ -804,7 +807,8 @@ Update team note
804807
```
805808
USAGE
806809
$ hackmd-cli team-notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>] [--permalink
807-
<value>] [--readPermission <value>] [--tags <value>] [--teamPath <value>] [--writePermission <value>]
810+
<value>] [--readPermission <value>] [--tags <value>] [--teamPath <value>] [--title <value>] [--writePermission
811+
<value>]
808812
809813
FLAGS
810814
-h, --help Show CLI help.
@@ -815,12 +819,15 @@ FLAGS
815819
--readPermission=<value> set note permission: owner, signed_in, guest
816820
--tags=<value> set note tags, comma-separated (e.g. tag1,tag2)
817821
--teamPath=<value> HackMD team path
822+
--title=<value> new note title
818823
--writePermission=<value> set note permission: owner, signed_in, guest
819824
820825
DESCRIPTION
821826
Update team note
822827
823828
EXAMPLES
829+
$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --title='A new title'
830+
824831
$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title'
825832
826833
$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title'

‎hackmd-cli.skill‎

17 Bytes
Binary file not shown.

‎hackmd-cli/SKILL.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ hackmd-cli notes create -e
6767

6868
# Update note
6969
hackmd-cli notes update --noteId=<id> --content='# New Content'
70+
hackmd-cli notes update --noteId=<id> --title='New title'
7071

7172
# Move note into a folder
7273
hackmd-cli notes update --noteId=<id> --parentFolderId=<folder-id>
@@ -89,6 +90,7 @@ hackmd-cli team-notes create --teamPath=<team-path> --parentFolderId=<folder-id>
8990

9091
# Update team note
9192
hackmd-cli team-notes update --teamPath=<team-path> --noteId=<id> --content='# Updated'
93+
hackmd-cli team-notes update --teamPath=<team-path> --noteId=<id> --title='New title'
9294

9395
# Move team note into a folder
9496
hackmd-cli team-notes update --teamPath=<team-path> --noteId=<id> --parentFolderId=<folder-id>
@@ -216,7 +218,7 @@ cat doc.md | hackmd-cli notes create --title="My Doc"
216218
hackmd-cli notes --filter=title="My Doc"
217219

218220
# Update existing note from file and verify
219-
cat doc.md | hackmd-cli notes update --noteId=<id>
221+
cat doc.md | hackmd-cli notes update --noteId=<id> --title="My Doc"
220222
hackmd-cli export --noteId=<id> | head -5
221223
```
222224

‎src/commands/notes/update.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import {Flags} from '@oclif/core'
44

55
import HackMDCommand from '../../command'
66
import {
7-
noteContent, noteId, notePermission, noteTags, parentFolderId, permalink,
7+
noteContent, noteId, notePermission, noteTags, noteTitle, parentFolderId, permalink,
88
} from '../../flags'
99
import {buildNoteUpdatePayload} from '../../note-update'
1010
import {safeStdinRead} from '../../utils'
1111

1212
export default class Update extends HackMDCommand {
1313
static description = 'Update note'
1414
static examples = [
15+
"$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --title='A new title'",
1516
"$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title'",
1617
"$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title'",
1718
'$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --readPermission=owner --writePermission=owner',
@@ -26,12 +27,13 @@ export default class Update extends HackMDCommand {
2627
permalink,
2728
readPermission: notePermission(),
2829
tags: noteTags,
30+
title: noteTitle,
2931
writePermission: notePermission(),
3032
}
3133

3234
async run() {
3335
const {flags} = await this.parse(Update)
34-
const {content, noteId, parentFolderId, permalink, readPermission, tags, writePermission} = flags
36+
const {content, noteId, parentFolderId, permalink, readPermission, tags, title, writePermission} = flags
3537

3638
if (!noteId) {
3739
this.error('Flag noteId could not be empty')
@@ -42,7 +44,7 @@ export default class Update extends HackMDCommand {
4244
try {
4345
payload = buildNoteUpdatePayload(
4446
{
45-
content, parentFolderId, permalink, readPermission, tags, writePermission,
47+
content, parentFolderId, permalink, readPermission, tags, title, writePermission,
4648
},
4749
stdinContent,
4850
)

‎src/commands/team-notes/update.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import {Flags} from '@oclif/core'
44

55
import HackMDCommand from '../../command'
66
import {
7-
noteContent, noteId, notePermission, noteTags, parentFolderId, permalink, teamPath,
7+
noteContent, noteId, notePermission, noteTags, noteTitle, parentFolderId, permalink, teamPath,
88
} from '../../flags'
99
import {buildNoteUpdatePayload} from '../../note-update'
1010
import {safeStdinRead} from '../../utils'
1111

1212
export default class Update extends HackMDCommand {
1313
static description = 'Update team note'
1414
static examples = [
15+
"$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --title='A new title'",
1516
"$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title'",
1617
"$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title'",
1718
'$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --readPermission=owner --writePermission=owner',
@@ -27,12 +28,13 @@ export default class Update extends HackMDCommand {
2728
readPermission: notePermission(),
2829
tags: noteTags,
2930
teamPath,
31+
title: noteTitle,
3032
writePermission: notePermission(),
3133
}
3234

3335
async run() {
3436
const {flags} = await this.parse(Update)
35-
const {content, noteId, parentFolderId, permalink, readPermission, tags, teamPath, writePermission} = flags
37+
const {content, noteId, parentFolderId, permalink, readPermission, tags, teamPath, title, writePermission} = flags
3638

3739
if (!teamPath) {
3840
this.error('Flag teamPath could not be empty')
@@ -47,7 +49,7 @@ export default class Update extends HackMDCommand {
4749
try {
4850
payload = buildNoteUpdatePayload(
4951
{
50-
content, parentFolderId, permalink, readPermission, tags, writePermission,
52+
content, parentFolderId, permalink, readPermission, tags, title, writePermission,
5153
},
5254
stdinContent,
5355
)

‎src/note-update.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ export type NoteUpdateFlags = {
66
permalink?: string
77
readPermission?: string
88
tags?: string
9+
title?: string
910
writePermission?: string
1011
}
1112

1213
export function buildNoteUpdatePayload(
13-
{content, parentFolderId, permalink, readPermission, tags, writePermission}: NoteUpdateFlags,
14+
{content, parentFolderId, permalink, readPermission, tags, title, writePermission}: NoteUpdateFlags,
1415
stdinContent?: string,
1516
): UpdateNoteOptions {
1617
if (stdinContent && content !== undefined) {
@@ -26,6 +27,7 @@ export function buildNoteUpdatePayload(
2627
if (writePermission !== undefined) payload.writePermission = writePermission as NotePermissionRole
2728
if (permalink !== undefined) payload.permalink = permalink
2829
if (tags !== undefined) payload.tags = tags.split(',').map(tag => tag.trim()).filter(Boolean)
30+
if (title !== undefined) payload.title = title
2931

3032
if (Object.keys(payload).length === 0) {
3133
throw new Error('Nothing to update')

‎test/note-update.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import {expect} from 'chai'
22

3+
import NotesUpdate from '../src/commands/notes/update'
4+
import TeamNotesUpdate from '../src/commands/team-notes/update'
35
import {buildNoteUpdatePayload} from '../src/note-update'
46

57
describe('Note update payload', () => {
8+
it('exposes --title for personal and team note updates', () => {
9+
expect(NotesUpdate.flags).to.have.property('title')
10+
expect(TeamNotesUpdate.flags).to.have.property('title')
11+
})
12+
613
it('uses piped stdin content without changing it', () => {
714
const content = '# Piped content\n\nBody with trailing newline.\n'
815

@@ -30,17 +37,23 @@ describe('Note update payload', () => {
3037
permalink: 'new-permalink',
3138
readPermission: 'guest',
3239
tags: ' tag1, tag2, ,',
40+
title: 'New title',
3341
writePermission: 'owner',
3442
})).to.deep.equal({
3543
parentFolderId: 'folder-id',
3644
permalink: 'new-permalink',
3745
readPermission: 'guest',
3846
tags: ['tag1', 'tag2'],
47+
title: 'New title',
3948
writePermission: 'owner',
4049
})
4150
})
4251

4352
it('allows an explicit empty --content value', () => {
4453
expect(buildNoteUpdatePayload({content: ''}, '')).to.deep.equal({content: ''})
4554
})
55+
56+
it('allows an explicit empty --title value', () => {
57+
expect(buildNoteUpdatePayload({title: ''})).to.deep.equal({title: ''})
58+
})
4659
})

0 commit comments

Comments
 (0)