@@ -2,22 +2,22 @@ import {
2
2
CommentPermissionType ,
3
3
CreateNoteOptions ,
4
4
NotePermissionRole ,
5
- } from " @hackmd/api/dist/type" ;
6
- import { CliUx , Flags } from " @oclif/core" ;
7
- import * as fs from "fs" ;
5
+ } from ' @hackmd/api/dist/type'
6
+ import { CliUx , Flags } from ' @oclif/core'
7
+ import * as fs from 'fs'
8
8
9
- import HackMDCommand from " ../../command" ;
9
+ import HackMDCommand from ' ../../command'
10
10
import {
11
11
commentPermission ,
12
12
noteContent ,
13
13
notePermission ,
14
14
noteTitle ,
15
- } from " ../../flags" ;
16
- import { safeStdinRead , temporaryMD } from " ../../utils" ;
17
- import openEditor from " ../../openEditor" ;
15
+ } from ' ../../flags'
16
+ import openEditor from ' ../../open-editor'
17
+ import { safeStdinRead , temporaryMD } from ' ../../utils'
18
18
19
19
export default class CreateCommand extends HackMDCommand {
20
- static description = " Create a note" ;
20
+ static description = ' Create a note'
21
21
22
22
static examples = [
23
23
"notes create --content='# A new note' --readPermission=owner --writePermission=owner --commentPermission=disabled" ,
@@ -26,73 +26,73 @@ export default class CreateCommand extends HackMDCommand {
26
26
────────────────────── ──────────────────────────────── ────────────────────── ────────
27
27
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null` ,
28
28
29
- " Or you can pipe content via Unix pipeline:" ,
30
- " cat README.md | hackmd-cli notes create" ,
31
- ] ;
29
+ ' Or you can pipe content via Unix pipeline:' ,
30
+ ' cat README.md | hackmd-cli notes create' ,
31
+ ]
32
32
33
33
static flags = {
34
- help : Flags . help ( { char : "h" } ) ,
34
+ help : Flags . help ( { char : 'h' } ) ,
35
35
title : noteTitle ( ) ,
36
36
content : noteContent ( ) ,
37
37
readPermission : notePermission ( ) ,
38
38
writePermission : notePermission ( ) ,
39
39
commentPermission : commentPermission ( ) ,
40
40
editor : Flags . boolean ( {
41
- char : "e" ,
42
- description : " create note with $EDITOR" ,
41
+ char : 'e' ,
42
+ description : ' create note with $EDITOR' ,
43
43
} ) ,
44
44
...CliUx . ux . table . flags ( ) ,
45
- } ;
45
+ }
46
46
47
47
async run ( ) {
48
- const { flags } = await this . parse ( CreateCommand ) ;
49
- const pipeString = safeStdinRead ( ) ;
48
+ const { flags} = await this . parse ( CreateCommand )
49
+ const pipeString = safeStdinRead ( )
50
50
51
51
const options : CreateNoteOptions = {
52
52
title : flags . title ,
53
53
content : pipeString || flags . content ,
54
54
readPermission : flags . readPermission as NotePermissionRole ,
55
55
writePermission : flags . writePermission as NotePermissionRole ,
56
56
commentPermission : flags . commentPermission as CommentPermissionType ,
57
- } ;
57
+ }
58
58
59
59
if ( flags . editor ) {
60
60
try {
61
- const mdFile = temporaryMD ( ) ;
62
- await openEditor ( mdFile ) ;
61
+ const mdFile = temporaryMD ( )
62
+ await openEditor ( mdFile )
63
63
64
- options . content = fs . readFileSync ( mdFile ) . toString ( ) ;
64
+ options . content = fs . readFileSync ( mdFile ) . toString ( )
65
65
} catch ( e ) {
66
- this . error ( e as Error ) ;
66
+ this . error ( e as Error )
67
67
}
68
68
}
69
69
70
70
try {
71
- const APIClient = await this . getAPIClient ( ) ;
72
- const note = await APIClient . createNote ( options ) ;
71
+ const APIClient = await this . getAPIClient ( )
72
+ const note = await APIClient . createNote ( options )
73
73
74
74
CliUx . ux . table (
75
75
[ note ] ,
76
76
{
77
77
id : {
78
- header : "ID" ,
78
+ header : 'ID' ,
79
79
} ,
80
80
title : { } ,
81
81
userPath : {
82
- header : " User path" ,
82
+ header : ' User path' ,
83
83
} ,
84
84
teamPath : {
85
- header : " Team path" ,
85
+ header : ' Team path' ,
86
86
} ,
87
87
} ,
88
88
{
89
89
printLine : this . log . bind ( this ) ,
90
90
...flags ,
91
91
}
92
- ) ;
92
+ )
93
93
} catch ( e ) {
94
- this . log ( " Create note failed" ) ;
95
- this . error ( e as Error ) ;
94
+ this . log ( ' Create note failed' )
95
+ this . error ( e as Error )
96
96
}
97
97
}
98
98
}
0 commit comments