@@ -9,33 +9,47 @@ if (import.meta.main) {
9
9
const docs = new Command ( )
10
10
. arguments ( "<path:file>" )
11
11
. description ( "Generate documentation from .env files" )
12
- . action ( async ( _options , path : string ) => {
13
- console . log (
14
- await parseAndConvert (
15
- path ,
16
- new DocsWriter ( ) ,
17
- ) ,
12
+ . option ( "-o, --output <path:string>" , "Output file path" )
13
+ . action ( async ( { output } , path ) => {
14
+ const markdown = await parseAndConvert (
15
+ path ,
16
+ new DocsWriter ( ) ,
18
17
) ;
18
+ if ( output ) {
19
+ await Deno . writeTextFile ( output , markdown ) ;
20
+ console . log ( `File written: ${ output } ` ) ;
21
+ } else {
22
+ console . log ( markdown ) ;
23
+ }
19
24
} ) ;
20
25
21
26
const envExample = new Command ( )
22
27
. arguments ( "<path:string>" )
23
28
. description ( "Generate example .env file" )
24
- . action ( async ( _options , path : string ) => {
25
- console . log (
26
- await parseAndConvert (
27
- path ,
28
- new EnvExampleWriter ( ) ,
29
- ) ,
29
+ . option ( "-r, --replace" , "Replace existing .env file" )
30
+ . option ( "-o, --output <path:string>" , "Output file path" )
31
+ . action ( async ( { replace , output } , path : string ) => {
32
+ const fileContents = await parseAndConvert (
33
+ path ,
34
+ new EnvExampleWriter ( ) ,
30
35
) ;
36
+ if ( replace || output ) {
37
+ await Deno . writeTextFile ( output ?? path , fileContents ) ;
38
+ console . log ( `File written: ${ output ?? path } ` ) ;
39
+ } else {
40
+ console . log ( fileContents ) ;
41
+ }
31
42
} ) ;
32
43
33
44
await new Command ( )
34
45
. name ( "envardoc" )
35
46
. version ( metadata . version )
36
47
. description ( metadata . description )
37
- . meta ( 'Deno' , Deno . version . deno )
38
- . meta ( 'FS Read Permissions' , Deno . permissions . querySync ( { name : "read" } ) . state )
48
+ . meta ( "Deno" , Deno . version . deno )
49
+ . meta (
50
+ "FS Read Permissions" ,
51
+ Deno . permissions . querySync ( { name : "read" } ) . state ,
52
+ )
39
53
. command ( "docs" , docs )
40
54
. command ( "example" , envExample )
41
55
. parse ( Deno . args ) ;
0 commit comments