2929# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3030# POSSIBILITY OF SUCH DAMAGE.
3131
32+ import argparse
3233import yaml
3334from yaml .parser import ParserError
3435from yaml .scanner import ScannerError
@@ -987,24 +988,13 @@ def __str__(self):
987988 code = j2_template .render (data , trim_blocks = True )
988989 return code
989990
990- def run (self ):
991- if 3 > len (sys .argv ) > 4 :
992- raise compile_error (
993- "generate_parameter_library_py expects three input argument: output_file, "
994- "yaml file path, [validate include header]"
995- )
996-
997- param_gen_directory = sys .argv [0 ].split ("/" )
998- param_gen_directory = "" .join (x + "/" for x in param_gen_directory [:- 1 ])
999- if param_gen_directory [- 1 ] != "/" :
1000- param_gen_directory += "/"
1001-
1002- output_file = sys .argv [1 ]
991+ def run (self , args ):
992+ output_file = args .output_cpp_header_file
1003993 output_dir = os .path .dirname (output_file )
1004994 if not os .path .isdir (output_dir ):
1005995 os .makedirs (output_dir )
1006996
1007- yaml_file = sys . argv [ 2 ]
997+ yaml_file = args . input_yaml_file
1008998 with open (yaml_file ) as f :
1009999 try :
10101000 docs = yaml .load_all (f , Loader = yaml .Loader )
@@ -1021,17 +1011,25 @@ def run(self):
10211011 self .namespace = list (doc .keys ())[0 ]
10221012 self .parse_dict (self .namespace , doc [self .namespace ], [])
10231013
1024- if len (sys .argv ) > 3 :
1025- self .user_validation_file = sys .argv [3 ]
1014+ self .user_validation_file = args .validate_header
10261015
10271016 code = str (self )
10281017 with open (output_file , "w" ) as f :
10291018 f .write (code )
10301019
10311020
1021+ def parse_args ():
1022+ parser = argparse .ArgumentParser ()
1023+ parser .add_argument ("output_cpp_header_file" )
1024+ parser .add_argument ("input_yaml_file" )
1025+ parser .add_argument ("validate_header" , nargs = "?" , default = "" )
1026+ return parser .parse_args ()
1027+
1028+
10321029def main ():
1030+ args = parse_args ()
10331031 gen_param_struct = GenerateCode ()
1034- gen_param_struct .run ()
1032+ gen_param_struct .run (args )
10351033
10361034
10371035if __name__ == "__main__" :
0 commit comments