@@ -36,6 +36,13 @@ def main() -> None:
36
36
default = "json" ,
37
37
help = "Specify the format of the output CWL files." ,
38
38
)
39
+ parser .add_argument (
40
+ "-p" ,
41
+ "--pretty" ,
42
+ action = "store_true" ,
43
+ default = False ,
44
+ help = "Beautify the output CWL document, only works with yaml format." ,
45
+ )
39
46
parser .add_argument (
40
47
"-C" ,
41
48
"--outdir" ,
@@ -46,10 +53,18 @@ def main() -> None:
46
53
options = parser .parse_args ()
47
54
48
55
with open (options .cwlfile , "r" ) as source_handle :
49
- run (source_handle , options .outdir , options .output_format , options .mainfile )
50
-
51
-
52
- def run (sourceIO : IO [str ], output_dir : str , output_format : str , mainfile : str ) -> None :
56
+ run (
57
+ source_handle ,
58
+ options .outdir ,
59
+ options .output_format ,
60
+ options .mainfile ,
61
+ options .pretty ,
62
+ )
63
+
64
+
65
+ def run (
66
+ sourceIO : IO [str ], output_dir : str , output_format : str , mainfile : str , pretty : bool
67
+ ) -> None :
53
68
"""Loop over the provided packed CWL document and split it up."""
54
69
source = yaml .main .round_trip_load (sourceIO , preserve_quotes = True )
55
70
add_lc_filename (source , sourceIO .name )
@@ -85,7 +100,7 @@ def my_represent_none(
85
100
if output_format == "json" :
86
101
json_dump (entry , output_file )
87
102
elif output_format == "yaml" :
88
- yaml_dump (entry , output_file )
103
+ yaml_dump (entry , output_file , pretty )
89
104
90
105
91
106
def rewrite (document : Any , doc_id : str ) -> Set [str ]:
@@ -212,9 +227,18 @@ def json_dump(entry: Any, output_file: str) -> None:
212
227
json .dump (entry , result_handle , indent = 4 )
213
228
214
229
215
- def yaml_dump (entry : Any , output_file : str ) -> None :
230
+ def yaml_dump (entry : Any , output_file : str , pretty : bool ) -> None :
216
231
with open (output_file , "w" , encoding = "utf-8" ) as result_handle :
217
- result_handle .write (stringify_dict (entry ))
232
+ if pretty :
233
+ result_handle .write (stringify_dict (entry ))
234
+ else :
235
+ yaml .main .round_trip_dump (
236
+ entry ,
237
+ result_handle ,
238
+ default_flow_style = False ,
239
+ indent = 4 ,
240
+ block_seq_indent = 2 ,
241
+ )
218
242
219
243
220
244
if __name__ == "__main__" :
0 commit comments