11import { CommentPermissionType , CreateNoteOptions , NotePermissionRole } from '@hackmd/api/dist/type'
22import { CliUx , Flags } from '@oclif/core'
3+ import fs from 'fs'
34
45import HackMDCommand from '../../command'
5- import { commentPermission , noteContent , notePermission , noteTitle , teamPath } from '../../flags'
6- import { safeStdinRead } from '../../utils'
6+ import { commentPermission , editor , noteContent , notePermission , noteTitle , teamPath } from '../../flags'
7+ import openEditor from '../../open-editor'
8+ import { safeStdinRead , temporaryMD } from '../../utils'
79
810export default class Create extends HackMDCommand {
911 static description = 'Create a team note'
@@ -26,6 +28,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
2628 readPermission : notePermission ( ) ,
2729 writePermission : notePermission ( ) ,
2830 commentPermission : commentPermission ( ) ,
31+ editor,
2932 ...CliUx . ux . table . flags ( ) ,
3033 }
3134
@@ -46,6 +49,17 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
4649 this . error ( 'Flag teamPath could not be empty' )
4750 }
4851
52+ if ( flags . editor ) {
53+ try {
54+ const mdFile = temporaryMD ( )
55+ await openEditor ( mdFile )
56+
57+ options . content = fs . readFileSync ( mdFile ) . toString ( )
58+ } catch ( e ) {
59+ this . error ( e as Error )
60+ }
61+ }
62+
4963 try {
5064 const APIClient = await this . getAPIClient ( )
5165 const note = await APIClient . createTeamNote ( teamPath , options )
0 commit comments