Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ Update note
```
USAGE
$ hackmd-cli notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>] [--permalink
<value>] [--readPermission <value>] [--tags <value>] [--writePermission <value>]
<value>] [--readPermission <value>] [--tags <value>] [--title <value>] [--writePermission <value>]

FLAGS
-h, --help Show CLI help.
Expand All @@ -533,12 +533,15 @@ FLAGS
--permalink=<value> note permalink
--readPermission=<value> set note permission: owner, signed_in, guest
--tags=<value> set note tags, comma-separated (e.g. tag1,tag2)
--title=<value> new note title
--writePermission=<value> 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'
Expand Down Expand Up @@ -804,7 +807,8 @@ Update team note
```
USAGE
$ hackmd-cli team-notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>] [--permalink
<value>] [--readPermission <value>] [--tags <value>] [--teamPath <value>] [--writePermission <value>]
<value>] [--readPermission <value>] [--tags <value>] [--teamPath <value>] [--title <value>] [--writePermission
<value>]

FLAGS
-h, --help Show CLI help.
Expand All @@ -815,12 +819,15 @@ FLAGS
--readPermission=<value> set note permission: owner, signed_in, guest
--tags=<value> set note tags, comma-separated (e.g. tag1,tag2)
--teamPath=<value> HackMD team path
--title=<value> new note title
--writePermission=<value> 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'
Expand Down
Binary file modified hackmd-cli.skill
Binary file not shown.
4 changes: 3 additions & 1 deletion hackmd-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ hackmd-cli notes create -e

# Update note
hackmd-cli notes update --noteId=<id> --content='# New Content'
hackmd-cli notes update --noteId=<id> --title='New title'

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

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

# Move team note into a folder
hackmd-cli team-notes update --teamPath=<team-path> --noteId=<id> --parentFolderId=<folder-id>
Expand Down Expand Up @@ -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=<id>
cat doc.md | hackmd-cli notes update --noteId=<id> --title="My Doc"
hackmd-cli export --noteId=<id> | head -5
```

Expand Down
8 changes: 5 additions & 3 deletions src/commands/notes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ 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'

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',
Expand All @@ -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')
Expand All @@ -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,
)
Expand Down
8 changes: 5 additions & 3 deletions src/commands/team-notes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ 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'

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',
Expand All @@ -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')
Expand All @@ -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,
)
Expand Down
4 changes: 3 additions & 1 deletion src/note-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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')
Expand Down
13 changes: 13 additions & 0 deletions test/note-update.test.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -30,17 +37,23 @@ 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',
})
})

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: ''})
})
})
Loading