diff --git a/README.md b/README.md index df0c672..04aa67e 100644 --- a/README.md +++ b/README.md @@ -523,7 +523,7 @@ Update note ``` USAGE $ hackmd-cli notes update [--content ] [-h] [--noteId ] [--parentFolderId ] [--permalink - ] [--readPermission ] [--tags ] [--writePermission ] + ] [--readPermission ] [--tags ] [--title ] [--writePermission ] FLAGS -h, --help Show CLI help. @@ -533,12 +533,15 @@ FLAGS --permalink= note permalink --readPermission= set note permission: owner, signed_in, guest --tags= set note tags, comma-separated (e.g. tag1,tag2) + --title= new note title --writePermission= set note permission: owner, signed_in, guest DESCRIPTION Update note EXAMPLES + $ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --title='A new title' + $ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title' $ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title' @@ -804,7 +807,8 @@ Update team note ``` USAGE $ hackmd-cli team-notes update [--content ] [-h] [--noteId ] [--parentFolderId ] [--permalink - ] [--readPermission ] [--tags ] [--teamPath ] [--writePermission ] + ] [--readPermission ] [--tags ] [--teamPath ] [--title ] [--writePermission + ] FLAGS -h, --help Show CLI help. @@ -815,12 +819,15 @@ FLAGS --readPermission= set note permission: owner, signed_in, guest --tags= set note tags, comma-separated (e.g. tag1,tag2) --teamPath= HackMD team path + --title= new note title --writePermission= set note permission: owner, signed_in, guest DESCRIPTION Update team note EXAMPLES + $ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --title='A new title' + $ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title' $ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title' diff --git a/hackmd-cli.skill b/hackmd-cli.skill index c3147ea..55ff35e 100644 Binary files a/hackmd-cli.skill and b/hackmd-cli.skill differ diff --git a/hackmd-cli/SKILL.md b/hackmd-cli/SKILL.md index b56962f..32b75df 100644 --- a/hackmd-cli/SKILL.md +++ b/hackmd-cli/SKILL.md @@ -67,6 +67,7 @@ hackmd-cli notes create -e # Update note hackmd-cli notes update --noteId= --content='# New Content' +hackmd-cli notes update --noteId= --title='New title' # Move note into a folder hackmd-cli notes update --noteId= --parentFolderId= @@ -89,6 +90,7 @@ hackmd-cli team-notes create --teamPath= --parentFolderId= # Update team note hackmd-cli team-notes update --teamPath= --noteId= --content='# Updated' +hackmd-cli team-notes update --teamPath= --noteId= --title='New title' # Move team note into a folder hackmd-cli team-notes update --teamPath= --noteId= --parentFolderId= @@ -216,7 +218,7 @@ cat doc.md | hackmd-cli notes create --title="My Doc" hackmd-cli notes --filter=title="My Doc" # Update existing note from file and verify -cat doc.md | hackmd-cli notes update --noteId= +cat doc.md | hackmd-cli notes update --noteId= --title="My Doc" hackmd-cli export --noteId= | head -5 ``` diff --git a/src/commands/notes/update.ts b/src/commands/notes/update.ts index 21ae05d..b0aae8b 100644 --- a/src/commands/notes/update.ts +++ b/src/commands/notes/update.ts @@ -4,7 +4,7 @@ import {Flags} from '@oclif/core' import HackMDCommand from '../../command' import { - noteContent, noteId, notePermission, noteTags, parentFolderId, permalink, + noteContent, noteId, notePermission, noteTags, noteTitle, parentFolderId, permalink, } from '../../flags' import {buildNoteUpdatePayload} from '../../note-update' import {safeStdinRead} from '../../utils' @@ -12,6 +12,7 @@ import {safeStdinRead} from '../../utils' export default class Update extends HackMDCommand { static description = 'Update note' static examples = [ + "$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --title='A new title'", "$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title'", "$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title'", '$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --readPermission=owner --writePermission=owner', @@ -26,12 +27,13 @@ export default class Update extends HackMDCommand { permalink, readPermission: notePermission(), tags: noteTags, + title: noteTitle, writePermission: notePermission(), } async run() { const {flags} = await this.parse(Update) - const {content, noteId, parentFolderId, permalink, readPermission, tags, writePermission} = flags + const {content, noteId, parentFolderId, permalink, readPermission, tags, title, writePermission} = flags if (!noteId) { this.error('Flag noteId could not be empty') @@ -42,7 +44,7 @@ export default class Update extends HackMDCommand { try { payload = buildNoteUpdatePayload( { - content, parentFolderId, permalink, readPermission, tags, writePermission, + content, parentFolderId, permalink, readPermission, tags, title, writePermission, }, stdinContent, ) diff --git a/src/commands/team-notes/update.ts b/src/commands/team-notes/update.ts index 5b92981..5f22e92 100644 --- a/src/commands/team-notes/update.ts +++ b/src/commands/team-notes/update.ts @@ -4,7 +4,7 @@ import {Flags} from '@oclif/core' import HackMDCommand from '../../command' import { - noteContent, noteId, notePermission, noteTags, parentFolderId, permalink, teamPath, + noteContent, noteId, notePermission, noteTags, noteTitle, parentFolderId, permalink, teamPath, } from '../../flags' import {buildNoteUpdatePayload} from '../../note-update' import {safeStdinRead} from '../../utils' @@ -12,6 +12,7 @@ import {safeStdinRead} from '../../utils' export default class Update extends HackMDCommand { static description = 'Update team note' static examples = [ + "$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --title='A new title'", "$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --content='# A new title'", "$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --content='# A new title'", '$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --readPermission=owner --writePermission=owner', @@ -27,12 +28,13 @@ export default class Update extends HackMDCommand { readPermission: notePermission(), tags: noteTags, teamPath, + title: noteTitle, writePermission: notePermission(), } async run() { const {flags} = await this.parse(Update) - const {content, noteId, parentFolderId, permalink, readPermission, tags, teamPath, writePermission} = flags + const {content, noteId, parentFolderId, permalink, readPermission, tags, teamPath, title, writePermission} = flags if (!teamPath) { this.error('Flag teamPath could not be empty') @@ -47,7 +49,7 @@ export default class Update extends HackMDCommand { try { payload = buildNoteUpdatePayload( { - content, parentFolderId, permalink, readPermission, tags, writePermission, + content, parentFolderId, permalink, readPermission, tags, title, writePermission, }, stdinContent, ) diff --git a/src/note-update.ts b/src/note-update.ts index 7d80736..ceaef4a 100644 --- a/src/note-update.ts +++ b/src/note-update.ts @@ -6,11 +6,12 @@ export type NoteUpdateFlags = { permalink?: string readPermission?: string tags?: string + title?: string writePermission?: string } export function buildNoteUpdatePayload( - {content, parentFolderId, permalink, readPermission, tags, writePermission}: NoteUpdateFlags, + {content, parentFolderId, permalink, readPermission, tags, title, writePermission}: NoteUpdateFlags, stdinContent?: string, ): UpdateNoteOptions { if (stdinContent && content !== undefined) { @@ -26,6 +27,7 @@ export function buildNoteUpdatePayload( if (writePermission !== undefined) payload.writePermission = writePermission as NotePermissionRole if (permalink !== undefined) payload.permalink = permalink if (tags !== undefined) payload.tags = tags.split(',').map(tag => tag.trim()).filter(Boolean) + if (title !== undefined) payload.title = title if (Object.keys(payload).length === 0) { throw new Error('Nothing to update') diff --git a/test/note-update.test.ts b/test/note-update.test.ts index be3b218..039bab1 100644 --- a/test/note-update.test.ts +++ b/test/note-update.test.ts @@ -1,8 +1,15 @@ import {expect} from 'chai' +import NotesUpdate from '../src/commands/notes/update' +import TeamNotesUpdate from '../src/commands/team-notes/update' import {buildNoteUpdatePayload} from '../src/note-update' describe('Note update payload', () => { + it('exposes --title for personal and team note updates', () => { + expect(NotesUpdate.flags).to.have.property('title') + expect(TeamNotesUpdate.flags).to.have.property('title') + }) + it('uses piped stdin content without changing it', () => { const content = '# Piped content\n\nBody with trailing newline.\n' @@ -30,12 +37,14 @@ describe('Note update payload', () => { permalink: 'new-permalink', readPermission: 'guest', tags: ' tag1, tag2, ,', + title: 'New title', writePermission: 'owner', })).to.deep.equal({ parentFolderId: 'folder-id', permalink: 'new-permalink', readPermission: 'guest', tags: ['tag1', 'tag2'], + title: 'New title', writePermission: 'owner', }) }) @@ -43,4 +52,8 @@ describe('Note update payload', () => { it('allows an explicit empty --content value', () => { expect(buildNoteUpdatePayload({content: ''}, '')).to.deep.equal({content: ''}) }) + + it('allows an explicit empty --title value', () => { + expect(buildNoteUpdatePayload({title: ''})).to.deep.equal({title: ''}) + }) })