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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package-lock.json
*-debug.log
*-error.log
/.nyc_output
Expand Down
60 changes: 40 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ Create a note
```
USAGE
$ hackmd-cli notes create [--commentPermission <value>] [--content <value>] [-e] [-h] [--parentFolderId <value>]
[--readPermission <value>] [--title <value>] [--writePermission <value>] [--columns <value> | -x] [--sort <value>]
[--filter <value>] [--output csv|json|yaml | | [--csv | --no-truncate]] [--no-header | ]
[--readPermission <value>] [--tags <value>] [--title <value>] [--writePermission <value>] [--columns <value> | -x]
[--sort <value>] [--filter <value>] [--output csv|json|yaml | | [--csv | --no-truncate]] [--no-header | ]

FLAGS
-e, --editor create note with $EDITOR
Expand All @@ -472,6 +472,7 @@ FLAGS
--parentFolderId=<value> parent folder id
--readPermission=<value> set note permission: owner, signed_in, guest
--sort=<value> property to sort by (prepend '-' for descending)
--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

Expand Down Expand Up @@ -515,25 +516,34 @@ EXAMPLES

## `hackmd-cli notes update`

Update note content
Update note

```
USAGE
$ hackmd-cli notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>]
$ hackmd-cli notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>] [--permalink <value>]
[--readPermission <value>] [--tags <value>] [--writePermission <value>]

FLAGS
-h, --help Show CLI help.
--content=<value> new note content
--noteId=<value> HackMD note id
--parentFolderId=<value> parent folder id
-h, --help Show CLI help.
--content=<value> new note content
--noteId=<value> HackMD note id
--parentFolderId=<value> parent folder id
--permalink=<value> note permalink
--readPermission=<value> set note permission: owner, signed_in, guest
--tags=<value> set note tags, comma-separated (e.g. tag1,tag2)
--writePermission=<value> set note permission: owner, signed_in, guest

DESCRIPTION
Update note content
Update note

EXAMPLES
$ 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

$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --tags=tag1,tag2
```

## `hackmd-cli team-folders`
Expand Down Expand Up @@ -719,8 +729,9 @@ Create a team note
```
USAGE
$ hackmd-cli team-notes create [--commentPermission <value>] [--content <value>] [-e] [-h] [--parentFolderId <value>]
[--readPermission <value>] [--teamPath <value>] [--title <value>] [--writePermission <value>] [--columns <value> |
-x] [--sort <value>] [--filter <value>] [--output csv|json|yaml | | [--csv | --no-truncate]] [--no-header | ]
[--readPermission <value>] [--tags <value>] [--teamPath <value>] [--title <value>] [--writePermission <value>]
[--columns <value> | -x] [--sort <value>] [--filter <value>] [--output csv|json|yaml | | [--csv | --no-truncate]]
[--no-header | ]

FLAGS
-e, --editor create note with $EDITOR
Expand All @@ -738,6 +749,7 @@ FLAGS
--parentFolderId=<value> parent folder id
--readPermission=<value> set note permission: owner, signed_in, guest
--sort=<value> property to sort by (prepend '-' for descending)
--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
Expand Down Expand Up @@ -783,27 +795,35 @@ EXAMPLES

## `hackmd-cli team-notes update`

Update team note content
Update team note

```
USAGE
$ hackmd-cli team-notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>] [--teamPath
<value>]
$ hackmd-cli team-notes update [--content <value>] [-h] [--noteId <value>] [--parentFolderId <value>]
[--permalink <value>] [--readPermission <value>] [--tags <value>] [--teamPath <value>] [--writePermission <value>]

FLAGS
-h, --help Show CLI help.
--content=<value> new note content
--noteId=<value> HackMD note id
--parentFolderId=<value> parent folder id
--teamPath=<value> HackMD team path
-h, --help Show CLI help.
--content=<value> new note content
--noteId=<value> HackMD note id
--parentFolderId=<value> parent folder id
--permalink=<value> note permalink
--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
--writePermission=<value> set note permission: owner, signed_in, guest

DESCRIPTION
Update team note content
Update team note

EXAMPLES
$ 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

$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --tags=tag1,tag2
```

## `hackmd-cli teams`
Expand Down
13 changes: 11 additions & 2 deletions src/commands/notes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
editor,
noteContent,
notePermission,
noteTags,
noteTitle,
parentFolderId,
} from '../../flags'
Expand Down Expand Up @@ -47,6 +48,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
help: Flags.help({char: 'h'}),
parentFolderId,
readPermission: notePermission,
tags: noteTags,
title: noteTitle,
writePermission: notePermission,
...ux.table.flags(),
Expand All @@ -56,7 +58,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
const {flags} = await this.parse(CreateCommand)
const pipeString = safeStdinRead()

const options: CreateNoteOptions = {
const options: CreateNoteOptions & {tags?: string[]} = {
commentPermission: flags.commentPermission as CommentPermissionType,
content: pipeString || flags.content,
parentFolderId: flags.parentFolderId,
Expand All @@ -65,6 +67,10 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
writePermission: flags.writePermission as NotePermissionRole,
}

if (flags.tags !== undefined) {
options.tags = flags.tags.split(',').map((t: string) => t.trim()).filter(Boolean)
}

if (flags.editor) {
try {
const mdFile = temporaryMD()
Expand All @@ -78,14 +84,17 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n

try {
const APIClient = await this.getAPIClient()
const note = await APIClient.createNote(options)
const note = await APIClient.createNote(options as CreateNoteOptions)

ux.table(
[note],
{
id: {
header: 'ID',
},
tags: {
get: row => (row.tags ?? []).join(', '),
},
teamPath: {
header: 'Team path',
},
Expand Down
3 changes: 3 additions & 0 deletions src/commands/notes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ raUuSTetT5uQbqQfLnz9lA CLI test note gvfz2UB5THiKABQJQnLs6Q n
id: {
header: 'ID',
},
tags: {
get: row => (row.tags ?? []).join(', '),
},
teamPath: {
header: 'Team Path',
},
Expand Down
32 changes: 22 additions & 10 deletions src/commands/notes/update.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
import type {UpdateNoteOptions} from '@hackmd/api'
import type {NotePermissionRole, UpdateNoteOptions} from '@hackmd/api'

import {Flags} from '@oclif/core'

import HackMDCommand from '../../command'
import {noteContent, noteId, parentFolderId} from '../../flags'
import {
noteContent, noteId, notePermission, noteTags, parentFolderId, permalink,
} from '../../flags'

export default class Update extends HackMDCommand {
static description = 'Update note content'
static description = 'Update note'
static examples = [
"$ 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',
'$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --tags=tag1,tag2',
]
static flags = {
content: noteContent,
help: Flags.help({char: 'h'}),
noteId,
parentFolderId,
permalink,
readPermission: notePermission,
tags: noteTags,
writePermission: notePermission,
}

async run() {
const {flags} = await this.parse(Update)
const {content, noteId, parentFolderId} = flags
const {content, noteId, parentFolderId, permalink, readPermission, tags, writePermission} = flags

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

const payload: UpdateNoteOptions = {
content,
parentFolderId,
}
const payload: UpdateNoteOptions & {tags?: string[]} = {}

if (content !== undefined) payload.content = content
if (parentFolderId !== undefined) payload.parentFolderId = parentFolderId
if (readPermission !== undefined) payload.readPermission = readPermission as NotePermissionRole
if (writePermission !== undefined) payload.writePermission = writePermission as NotePermissionRole
if (permalink !== undefined) payload.permalink = permalink
if (tags !== undefined) payload.tags = tags.split(',').map((t: string) => t.trim()).filter(Boolean)

try {
const APIClient = await this.getAPIClient()
await APIClient.updateNote(noteId, payload)
await APIClient.updateNote(noteId, payload as UpdateNoteOptions)
} catch (error) {
this.log('Update note content failed')
this.log('Update note failed')
this.error(error as Error)
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/commands/team-notes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from 'node:fs'

import HackMDCommand from '../../command'
import {
commentPermission, editor, noteContent, notePermission, noteTitle, parentFolderId, teamPath,
commentPermission, editor, noteContent, notePermission, noteTags, noteTitle, parentFolderId, teamPath,
} from '../../flags'
import {openEditor} from '../../open-editor'
import {safeStdinRead, temporaryMD} from '../../utils'
Expand Down Expand Up @@ -38,6 +38,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
help: Flags.help({char: 'h'}),
parentFolderId,
readPermission: notePermission,
tags: noteTags,
teamPath,
title: noteTitle,
writePermission: notePermission,
Expand All @@ -48,8 +49,8 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
const {flags} = await this.parse(Create)
const pipeString = safeStdinRead()

const {commentPermission, content, parentFolderId, readPermission, teamPath, title, writePermission} = flags
const options: CreateNoteOptions = {
const {commentPermission, content, parentFolderId, readPermission, tags, teamPath, title, writePermission} = flags
const options: CreateNoteOptions & {tags?: string[]} = {
commentPermission: commentPermission as CommentPermissionType,
content: pipeString || content,
parentFolderId,
Expand All @@ -58,6 +59,10 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
writePermission: writePermission as NotePermissionRole,
}

if (tags !== undefined) {
options.tags = tags.split(',').map((t: string) => t.trim()).filter(Boolean)
}

if (!teamPath) {
this.error('Flag teamPath could not be empty')
}
Expand All @@ -75,12 +80,15 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n

try {
const APIClient = await this.getAPIClient()
const note = await APIClient.createTeamNote(teamPath, options)
const note = await APIClient.createTeamNote(teamPath, options as CreateNoteOptions)

ux.table([note], {
id: {
header: 'ID',
},
tags: {
get: row => (row.tags ?? []).join(', '),
},
teamPath: {
header: 'Team path',
},
Expand Down
3 changes: 3 additions & 0 deletions src/commands/team-notes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ BnC6gN0_TfStV2KKmPPXeg Welcome to your team's workspace null CLI-test`,
id: {
header: 'ID',
},
tags: {
get: row => (row.tags ?? []).join(', '),
},
teamPath: {
header: 'Team path',
},
Expand Down
30 changes: 20 additions & 10 deletions src/commands/team-notes/update.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import type {UpdateNoteOptions} from '@hackmd/api'
import type {NotePermissionRole, UpdateNoteOptions} from '@hackmd/api'

import {Flags} from '@oclif/core'

import HackMDCommand from '../../command'
import {
noteContent, noteId, parentFolderId, teamPath,
noteContent, noteId, notePermission, noteTags, parentFolderId, permalink, teamPath,
} from '../../flags'

export default class Update extends HackMDCommand {
static description = 'Update team note content'
static description = 'Update team note'
static examples = [
"$ 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',
'$ hackmd-cli team-notes update --teamPath=CLI-test --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --tags=tag1,tag2',
]
static flags = {
content: noteContent,
help: Flags.help({char: 'h'}),
noteId,
parentFolderId,
permalink,
readPermission: notePermission,
tags: noteTags,
teamPath,
writePermission: notePermission,
}

async run() {
const {flags} = await this.parse(Update)
const {content, noteId, parentFolderId, teamPath} = flags
const {content, noteId, parentFolderId, permalink, readPermission, tags, teamPath, writePermission} = flags

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

const payload: UpdateNoteOptions = {
content,
parentFolderId,
}
const payload: UpdateNoteOptions & {tags?: string[]} = {}

if (content !== undefined) payload.content = content
if (parentFolderId !== undefined) payload.parentFolderId = parentFolderId
if (readPermission !== undefined) payload.readPermission = readPermission as NotePermissionRole
if (writePermission !== undefined) payload.writePermission = writePermission as NotePermissionRole
if (permalink !== undefined) payload.permalink = permalink
if (tags !== undefined) payload.tags = tags.split(',').map((t: string) => t.trim()).filter(Boolean)

try {
const APIClient = await this.getAPIClient()
await APIClient.updateTeamNote(teamPath, noteId, payload)
await APIClient.updateTeamNote(teamPath, noteId, payload as UpdateNoteOptions)
} catch (error) {
this.log('Update team note content failed')
this.log('Update team note failed')
this.error(error as Error)
}
}
Expand Down
Loading
Loading