Skip to content
Draft
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: 39 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ Create a note
```
USAGE
$ hackmd-cli notes create [--commentPermission <value>] [--content <value>] [-e] [-h] [--readPermission <value>]
[--title <value>] [--writePermission <value>] [--columns <value> | -x] [--sort <value>] [--filter <value>] [--output
[--tags <value>] [--title <value>] [--writePermission <value>] [--columns <value> | -x] [--sort <value>] [--filter <value>] [--output
csv|json|yaml | | [--csv | --no-truncate]] [--no-header | ]

FLAGS
Expand All @@ -325,6 +325,7 @@ FLAGS
<options: csv|json|yaml>
--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 All @@ -334,9 +335,9 @@ DESCRIPTION
EXAMPLES
notes create --content='# A new note' --readPermission=owner --writePermission=owner --commentPermission=disabled

ID Title User Path Team Path
────────────────────── ──────────────────────────────── ────────────────────── ────────
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null
ID Title Tags User Path Team Path
────────────────────── ──────────────────────────────── ──────── ────────────────────── ────────
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null

Or you can pipe content via Unix pipeline:

Expand Down Expand Up @@ -364,22 +365,30 @@ EXAMPLES

## `hackmd-cli notes update`

Update note content
Update note

```
USAGE
$ hackmd-cli notes update [--content <value>] [-h] [--noteId <value>]
$ hackmd-cli notes update [--content <value>] [-h] [--noteId <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
-h, --help Show CLI help.
--content=<value> new note content
--noteId=<value> HackMD note 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 --readPermission=owner --writePermission=owner

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

## `hackmd-cli team-notes`
Expand Down Expand Up @@ -424,7 +433,7 @@ Create a team note
```
USAGE
$ hackmd-cli team-notes create [--commentPermission <value>] [--content <value>] [-e] [-h] [--readPermission <value>]
[--teamPath <value>] [--title <value>] [--writePermission <value>] [--columns <value> | -x] [--sort <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
Expand All @@ -442,6 +451,7 @@ FLAGS
<options: csv|json|yaml>
--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 All @@ -451,9 +461,9 @@ DESCRIPTION

EXAMPLES
team-notes:create --teamPath=CLI-test --content='# A new note' --readPermission=owner --writePermission=owner --commentPermission=disabled
ID Title User Path Team Path
────────────────────── ──────────────────────────────── ────────────────────── ────────
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null
ID Title Tags User Path Team Path
────────────────────── ──────────────────────────────── ──────── ────────────────────── ────────
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null

Or you can pipe content via Unix pipeline:

Expand Down Expand Up @@ -482,23 +492,31 @@ EXAMPLES

## `hackmd-cli team-notes update`

Update team note content
Update team note

```
USAGE
$ hackmd-cli team-notes update [--content <value>] [-h] [--noteId <value>] [--teamPath <value>]
$ hackmd-cli team-notes update [--content <value>] [-h] [--noteId <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
--teamPath=<value> HackMD team path
-h, --help Show CLI help.
--content=<value> new note content
--noteId=<value> HackMD note 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 --readPermission=owner --writePermission=owner

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

## `hackmd-cli teams`
Expand Down
19 changes: 14 additions & 5 deletions src/commands/notes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
editor,
noteContent,
notePermission,
noteTags,
noteTitle,
} from '../../flags'
import {openEditor} from '../../open-editor'
Expand All @@ -22,9 +23,9 @@ export default class CreateCommand extends HackMDCommand {
static examples = [
"notes create --content='# A new note' --readPermission=owner --writePermission=owner --commentPermission=disabled",

`ID Title User Path Team Path
────────────────────── ──────────────────────────────── ────────────────────── ────────
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null`,
`ID Title Tags User Path Team Path
────────────────────── ──────────────────────────────── ──────── ────────────────────── ────────
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null`,

'Or you can pipe content via Unix pipeline:',
'cat README.md | hackmd-cli notes create',
Expand All @@ -35,6 +36,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q
editor,
help: Flags.help({char: 'h'}),
readPermission: notePermission,
tags: noteTags,
title: noteTitle,
writePermission: notePermission,
...ux.table.flags(),
Expand All @@ -44,14 +46,18 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q
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,
readPermission: flags.readPermission as NotePermissionRole,
title: flags.title,
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 @@ -65,14 +71,17 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q

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
27 changes: 22 additions & 5 deletions src/commands/notes/update.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
import {NotePermissionRole} from '@hackmd/api/dist/type'
import {Flags} from '@oclif/core'

import HackMDCommand from '../../command'
import {noteContent, noteId} from '../../flags'
import {
noteContent, noteId, notePermission, noteTags, 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 --readPermission=owner --writePermission=owner',
'$ hackmd-cli notes update --noteId=WNkLM6gkS0Cg2cQ8rv7bYA --tags=tag1,tag2',
]
static flags = {
content: noteContent,
help: Flags.help({char: 'h'}),
noteId,
permalink,
readPermission: notePermission,
tags: noteTags,
writePermission: notePermission,
}

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

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

const payload: Parameters<Awaited<ReturnType<typeof this.getAPIClient>>['updateNote']>[1] & {tags?: string[]} = {}

if (content !== undefined) payload.content = content
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.updateNoteContent(noteId, content)
await APIClient.updateNote(noteId, payload as Parameters<Awaited<ReturnType<typeof this.getAPIClient>>['updateNote']>[1])
} catch (error) {
this.log('Update note content failed')
this.log('Update note failed')
this.error(error as Error)
}
}
Expand Down
22 changes: 15 additions & 7 deletions src/commands/team-notes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'node:fs'

import HackMDCommand from '../../command'
import {
commentPermission, editor, noteContent, notePermission, noteTitle, teamPath,
commentPermission, editor, noteContent, notePermission, noteTags, noteTitle, teamPath,
} from '../../flags'
import {openEditor} from '../../open-editor'
import {safeStdinRead, temporaryMD} from '../../utils'
Expand All @@ -13,9 +13,9 @@ export default class Create extends HackMDCommand {
static description = 'Create a team note'
static examples = [
`team-notes:create --teamPath=CLI-test --content='# A new note' --readPermission=owner --writePermission=owner --commentPermission=disabled
ID Title User Path Team Path
────────────────────── ──────────────────────────────── ────────────────────── ────────
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null `,
ID Title Tags User Path Team Path
────────────────────── ──────────────────────────────── ──────── ────────────────────── ────────
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null `,

'Or you can pipe content via Unix pipeline:',
'cat README.md | hackmd-cli notes create --teamPath=CLI-test',
Expand All @@ -26,6 +26,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
editor,
help: Flags.help({char: 'h'}),
readPermission: notePermission,
tags: noteTags,
teamPath,
title: noteTitle,
writePermission: notePermission,
Expand All @@ -36,15 +37,19 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
const {flags} = await this.parse(Create)
const pipeString = safeStdinRead()

const {commentPermission, content, readPermission, teamPath, title, writePermission} = flags
const options: CreateNoteOptions = {
const {commentPermission, content, readPermission, teamPath, tags, title, writePermission} = flags
const options: CreateNoteOptions & {tags?: string[]} = {
commentPermission: commentPermission as CommentPermissionType,
content: pipeString || content,
readPermission: readPermission as NotePermissionRole,
title,
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 @@ -62,12 +67,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
Loading