Skip to content

feat: support --editor option for team note creation #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2023
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
6 changes: 2 additions & 4 deletions src/commands/notes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as fs from 'fs'
import HackMDCommand from '../../command'
import {
commentPermission,
editor,
noteContent,
notePermission,
noteTitle,
Expand Down Expand Up @@ -37,10 +38,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q
readPermission: notePermission(),
writePermission: notePermission(),
commentPermission: commentPermission(),
editor: Flags.boolean({
char: 'e',
description: 'create note with $EDITOR',
}),
editor,
...CliUx.ux.table.flags(),
}

Expand Down
18 changes: 16 additions & 2 deletions src/commands/team-notes/create.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {CommentPermissionType, CreateNoteOptions, NotePermissionRole} from '@hackmd/api/dist/type'
import {CliUx, Flags} from '@oclif/core'
import fs from 'fs'

import HackMDCommand from '../../command'
import {commentPermission, noteContent, notePermission, noteTitle, teamPath} from '../../flags'
import {safeStdinRead} from '../../utils'
import {commentPermission, editor, noteContent, notePermission, noteTitle, teamPath} from '../../flags'
import openEditor from '../../open-editor'
import {safeStdinRead, temporaryMD} from '../../utils'

export default class Create extends HackMDCommand {
static description = 'Create a team note'
Expand All @@ -26,6 +28,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
readPermission: notePermission(),
writePermission: notePermission(),
commentPermission: commentPermission(),
editor,
...CliUx.ux.table.flags(),
}

Expand All @@ -46,6 +49,17 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
this.error('Flag teamPath could not be empty')
}

if (flags.editor) {
try {
const mdFile = temporaryMD()
await openEditor(mdFile)

options.content = fs.readFileSync(mdFile).toString()
} catch (e) {
this.error(e as Error)
}
}

try {
const APIClient = await this.getAPIClient()
const note = await APIClient.createTeamNote(teamPath, options)
Expand Down
5 changes: 5 additions & 0 deletions src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ export const notePermission = Flags.build({
export const commentPermission = Flags.build({
description: 'set comment permission: disabled, forbidden, owners, signed_in_users, everyone'
})

export const editor = Flags.boolean({
char: 'e',
description: 'create note with $EDITOR',
})