2323 required = True ,
2424 help = "Product group name to add the firmware" ,
2525)
26+ @click .option (
27+ "--analysis-configuration" ,
28+ "analysis_configuration_name" ,
29+ default = "Default" ,
30+ show_default = True ,
31+ required = True ,
32+ help = "Analysis configuration name" ,
33+ )
2634@click .option ("--version" , help = "Firmware version" )
2735@click .option ("--name" , help = "Firmware name" )
2836@click .argument ("filename" , type = click .Path (exists = True , path_type = Path ))
@@ -32,22 +40,17 @@ def upload_firmware(
3240 product_name : str ,
3341 vendor_name : str ,
3442 product_group_name : str ,
43+ analysis_configuration_name : str ,
3544 version : Optional [str ],
3645 name : Optional [str ],
3746 filename : Path ,
3847):
3948 """Uploads a firmware to the ONEKEY platform"""
4049
41- product_groups = client .get_product_groups ()
42-
43- try :
44- product_group_id = product_groups [product_group_name ]
45- except KeyError :
46- click .echo (f"Missing product group: { product_group_name } " )
47- click .echo ("Available product groups:" )
48- for pg in product_groups .keys ():
49- click .echo (f"- { pg } " )
50- sys .exit (10 )
50+ product_group_id = _get_product_group_id_by_name (client , product_group_name )
51+ analysis_configuration_id = _get_analysis_configuration_id_by_name (
52+ client , analysis_configuration_name
53+ )
5154
5255 if name is None :
5356 name = (
@@ -62,6 +65,7 @@ def upload_firmware(
6265 product_name = product_name ,
6366 product_group_id = product_group_id ,
6467 version = version ,
68+ analysis_configuration_id = analysis_configuration_id ,
6569 )
6670
6771 try :
@@ -72,3 +76,31 @@ def upload_firmware(
7276 for error in e ._errors :
7377 click .echo (f"- { error ['message' ]} " )
7478 sys .exit (11 )
79+
80+
81+ def _get_product_group_id_by_name (client : Client , product_group_name : str ):
82+ product_groups = client .get_product_groups ()
83+
84+ try :
85+ return product_groups [product_group_name ]
86+ except KeyError :
87+ click .echo (f"Missing product group: { product_group_name } " )
88+ click .echo ("Available product groups:" )
89+ for pg in product_groups .keys ():
90+ click .echo (f"- { pg } " )
91+ sys .exit (10 )
92+
93+
94+ def _get_analysis_configuration_id_by_name (
95+ client : Client , analysis_configuration_name : str
96+ ):
97+ analysis_configurations = client .get_analysis_configurations ()
98+
99+ try :
100+ return analysis_configurations [analysis_configuration_name ]
101+ except KeyError :
102+ click .echo (f"Missing analysis configuration { analysis_configuration_name } " )
103+ click .echo ("Available analysis configurations:" )
104+ for config in analysis_configurations .keys ():
105+ click .echo (f"- { config } " )
106+ sys .exit (12 )
0 commit comments