1313# "active": True
1414# }
1515
16+
1617def render_json_template (input_template_path , output_file_path , parameters ):
1718 if not os .path .exists (input_template_path ):
1819 raise FileNotFoundError (f"Template file not found: { input_template_path } " )
1920
20- with open (input_template_path , 'r' ) as f :
21+ with open (input_template_path , "r" ) as f :
2122 try :
2223 json_data = json .load (f )
2324 except json .JSONDecodeError as e :
@@ -29,20 +30,27 @@ def set_nested_value(data, keys, value):
2930 data [keys [- 1 ]] = value
3031
3132 for json_path , value in parameters .items ():
32- keys = json_path .split ('/' )
33+ keys = json_path .split ("/" )
3334 set_nested_value (json_data , keys , value )
3435
35- with open (output_file_path , 'w' ) as f :
36+ with open (output_file_path , "w" ) as f :
3637 json .dump (json_data , f , indent = 4 )
3738
39+
3840def main ():
39- parser = argparse .ArgumentParser (description = "Render a JSON template with parameters." )
40- parser .add_argument ("--template" , required = True , help = "Path to the input JSON template file." )
41- parser .add_argument ("--output" , required = True , help = "Path to the output rendered JSON file." )
41+ parser = argparse .ArgumentParser (
42+ description = "Render a JSON template with parameters."
43+ )
44+ parser .add_argument (
45+ "--template" , required = True , help = "Path to the input JSON template file."
46+ )
47+ parser .add_argument (
48+ "--output" , required = True , help = "Path to the output rendered JSON file."
49+ )
4250 parser .add_argument (
4351 "--parameters" ,
4452 required = True ,
45- help = 'Parameters as a single string, e.g., "key1=value1 key2=value2 key3=value3".'
53+ help = 'Parameters as a single string, e.g., "key1=value1 key2=value2 key3=value3".' ,
4654 )
4755 args = parser .parse_args ()
4856 # Resolve relative paths to absolute paths
@@ -65,5 +73,6 @@ def main():
6573 # Call the main function
6674 render_json_template (input_template_path , output_file_path , parameters )
6775
76+
6877if __name__ == "__main__" :
6978 main ()
0 commit comments