@@ -9,33 +9,47 @@ if (import.meta.main) {
99 const docs = new Command ( )
1010 . arguments ( "<path:file>" )
1111 . 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 ( ) ,
1817 ) ;
18+ if ( output ) {
19+ await Deno . writeTextFile ( output , markdown ) ;
20+ console . log ( `File written: ${ output } ` ) ;
21+ } else {
22+ console . log ( markdown ) ;
23+ }
1924 } ) ;
2025
2126 const envExample = new Command ( )
2227 . arguments ( "<path:string>" )
2328 . 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 ( ) ,
3035 ) ;
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+ }
3142 } ) ;
3243
3344 await new Command ( )
3445 . name ( "envardoc" )
3546 . version ( metadata . version )
3647 . 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+ )
3953 . command ( "docs" , docs )
4054 . command ( "example" , envExample )
4155 . parse ( Deno . args ) ;
0 commit comments