@@ -187,28 +187,51 @@ def main():
187187 "input_file" , type = str , help = "Path to the input ReqIF file."
188188 )
189189 main_parser .add_argument (
190- "output_dir" , type = str , help = "Path to the output dir."
190+ "--output-dir" ,
191+ type = str ,
192+ help = "Path to the output dir." ,
193+ default = "output/" ,
194+ )
195+ main_parser .add_argument (
196+ "--stdout" ,
197+ help = "Makes the script write the output ReqIF to standard output." ,
198+ action = "store_true" ,
199+ )
200+ main_parser .add_argument (
201+ "--no-filesystem" ,
202+ help = (
203+ "Disables writing to the file system. "
204+ "Should be used in combination with --stdout."
205+ ),
206+ action = "store_true" ,
191207 )
192208
193209 args = main_parser .parse_args ()
194210 input_file : str = args .input_file
211+ should_use_file_system : bool = not args .no_filesystem
212+ should_use_stdout : bool = args .stdout
213+
195214 if input_file .endswith (".reqifz" ):
196215 reqifz_bundle : ReqIFZBundle = ReqIFZParser .parse (input_file )
197216 assert len (reqifz_bundle .reqif_bundles ) == 1
198217 reqif_bundle = (list (reqifz_bundle .reqif_bundles .values ()))[0 ]
199218 else :
200219 reqif_bundle = ReqIFParser .parse (input_file )
201220
202- path_to_output_dir = args .output_dir
203- Path (path_to_output_dir ).mkdir (exist_ok = True )
204-
205221 req_dict = ReqIFToDictConverter .convert (reqif_bundle )
222+ reqif_json = json .dumps (req_dict .get_as_dict (), indent = 4 )
206223
207- path_to_output_file = os .path .join (path_to_output_dir , "output.json" )
208- with open (path_to_output_file , "w" , encoding = "utf8" ) as json_file :
209- json .dump (
210- req_dict .get_as_dict (), json_file , ensure_ascii = False , indent = 4
211- )
224+ if should_use_file_system :
225+ path_to_output_dir = args .output_dir
226+ Path (path_to_output_dir ).mkdir (exist_ok = True )
227+
228+ path_to_output_file = os .path .join (path_to_output_dir , "output.json" )
229+ with open (path_to_output_file , "w" , encoding = "utf8" ) as json_file :
230+ json_file .write (reqif_json )
231+ json_file .write ("\n " )
232+
233+ if should_use_stdout :
234+ print (reqif_json ) # noqa: T201
212235
213236
214237main ()
0 commit comments