1
1
import { CommentPermissionType , CreateNoteOptions , NotePermissionRole } from '@hackmd/api/dist/type'
2
2
import { CliUx , Flags } from '@oclif/core'
3
+ import fs from 'fs'
3
4
4
5
import 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'
7
9
8
10
export default class Create extends HackMDCommand {
9
11
static description = 'Create a team note'
@@ -26,6 +28,7 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
26
28
readPermission : notePermission ( ) ,
27
29
writePermission : notePermission ( ) ,
28
30
commentPermission : commentPermission ( ) ,
31
+ editor,
29
32
...CliUx . ux . table . flags ( ) ,
30
33
}
31
34
@@ -46,6 +49,17 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
46
49
this . error ( 'Flag teamPath could not be empty' )
47
50
}
48
51
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
+
49
63
try {
50
64
const APIClient = await this . getAPIClient ( )
51
65
const note = await APIClient . createTeamNote ( teamPath , options )
0 commit comments