2424Options: 
2525  --help, -h    Show this message. 
2626  --json, -j    Output JSON. 
27+   --indent 2    Output pretty-printed data, indented by the given number of spaces. 
2728
2829Additional options for bare "yaml" command: 
2930  --doc, -d     Output pretty-printed JS Document objects. 
@@ -55,6 +56,7 @@ export async function cli(
5556      options : { 
5657        doc : {  type : 'boolean' ,  short : 'd'  } , 
5758        help : {  type : 'boolean' ,  short : 'h'  } , 
59+         indent : {  type : 'string' ,  short : 'i'  } , 
5860        json : {  type : 'boolean' ,  short : 'j'  } , 
5961        single : {  type : 'boolean' ,  short : '1'  } , 
6062        strict : {  type : 'boolean' ,  short : 's'  } , 
@@ -71,6 +73,8 @@ export async function cli(
7173    values : opt 
7274  }  =  args 
7375
76+   let  indent  =  Number ( opt . indent ) 
77+ 
7478  stdin . setEncoding ( 'utf-8' ) 
7579
7680  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing 
@@ -92,7 +96,7 @@ export async function cli(
9296      } ) 
9397      stdin . on ( 'end' ,  ( )  =>  { 
9498        for  ( const  tok  of  lexer . lex ( '' ,  false ) )  add ( tok ) 
95-         if  ( opt . json )  console . log ( JSON . stringify ( data ) ) 
99+         if  ( opt . json )  console . log ( JSON . stringify ( data ,   null ,   indent ) ) 
96100        done ( ) 
97101      } ) 
98102      break 
@@ -110,7 +114,7 @@ export async function cli(
110114      } ) 
111115      stdin . on ( 'end' ,  ( )  =>  { 
112116        for  ( const  tok  of  parser . parse ( '' ,  false ) )  add ( tok ) 
113-         if  ( opt . json )  console . log ( JSON . stringify ( data ) ) 
117+         if  ( opt . json )  console . log ( JSON . stringify ( data ,   null ,   indent ) ) 
114118        done ( ) 
115119      } ) 
116120      break 
@@ -159,7 +163,8 @@ export async function cli(
159163        }  else  { 
160164          if  ( reqDocEnd )  console . log ( '...' ) 
161165          try  { 
162-             const  str  =  String ( doc ) 
166+             indent  ||=  2 
167+             const  str  =  doc . toString ( {  indent } ) 
163168            console . log ( str . endsWith ( '\n' )  ? str . slice ( 0 ,  - 1 )  : str ) 
164169          }  catch  ( error )  { 
165170            done ( error  as  Error ) 
@@ -188,7 +193,7 @@ export async function cli(
188193          ) 
189194        } 
190195        if  ( mode  !==  'valid'  &&  opt . json )  { 
191-           console . log ( JSON . stringify ( opt . single  ? data [ 0 ]  : data ) ) 
196+           console . log ( JSON . stringify ( opt . single  ? data [ 0 ]  : data ,   null ,   indent ) ) 
192197        } 
193198        done ( ) 
194199      } ) 
0 commit comments