1717logger = logging .getLogger ('intezer_cli' )
1818
1919
20+ class AliasedGroup (click .Group ):
21+ def get_command (self , ctx , cmd_name ):
22+ rv = click .Group .get_command (self , ctx , cmd_name )
23+ if rv is not None :
24+ return rv
25+ matches = [x for x in self .list_commands (ctx )
26+ if x .replace ('-' , '_' ) == cmd_name .replace ('-' , '_' )]
27+ if not matches :
28+ return None
29+ elif len (matches ) == 1 :
30+ return click .Group .get_command (self , ctx , matches [0 ])
31+ ctx .fail (f"Too many matches: { ', ' .join (sorted (matches ))} " )
32+
33+ def resolve_command (self , ctx , args ):
34+ # always return the full command name
35+ _ , cmd , args = super ().resolve_command (ctx , args )
36+ return cmd .name , cmd , args
37+
38+
2039def create_global_api ():
2140 try :
2241 api_key = key_store .get_stored_api_key ()
@@ -41,7 +60,7 @@ def create_global_api():
4160 raise click .Abort ()
4261
4362
44- @click .group (context_settings = dict (help_option_names = ['-h' , '--help' ], max_content_width = 120 ),
63+ @click .group (cls = AliasedGroup , context_settings = dict (help_option_names = ['-h' , '--help' ], max_content_width = 120 ),
4564 help = f'Intezer Labs Ltd. Intezer Analyze CLI { __version__ } ' )
4665def main_cli ():
4766 pass
@@ -135,7 +154,7 @@ def analyze(path: str,
135154 f'and attach the log file in { utilities .log_file_path } ' )
136155
137156
138- @main_cli .command ('analyze_by_list ' , short_help = 'Send a text file with list of hashes' )
157+ @main_cli .command ('analyze-by-list ' , short_help = 'Send a text file with list of hashes' )
139158@click .argument ('path' , type = click .Path (exists = True , dir_okay = False ))
140159def analyze_by_list (path ):
141160 """ Send a text file with hashes for analysis in Intezer Analyze.
@@ -146,7 +165,7 @@ def analyze_by_list(path):
146165 \b
147166 Examples:
148167 Send txt file with hashes for analysis:
149- $ intezer-analyze analyze_by_list ~/files/hashes.txt
168+ $ intezer-analyze analyze-by-list ~/files/hashes.txt
150169 """
151170 try :
152171 create_global_api ()
@@ -159,8 +178,7 @@ def analyze_by_list(path):
159178 click .echo ('Unexpected error occurred, please contact us at support@intezer.com '
160179 f'and attach the log file in { utilities .log_file_path } ' )
161180
162-
163- @main_cli .command ('index_by_list' , short_help = 'Send a text file with list of hashes, verdict, family name if malicious' )
181+ @main_cli .command ('index-by-list' , short_help = 'Send a text file with list of hashes, verdict, family name if malicious' )
164182@click .argument ('path' , type = click .Path (exists = True , dir_okay = False ))
165183@click .option ('--index-as' , type = click .Choice (['malicious' , 'trusted' ], case_sensitive = True ))
166184@click .argument ('family_name' , required = False , type = click .STRING , default = None )
@@ -173,7 +191,7 @@ def index_by_list(path: str, index_as: str, family_name: str):
173191
174192 \b
175193 Examples:
176- $ intezer-analyze index_by_list ~/files/hashes.txt malicious family_name
194+ $ intezer-analyze index-by-list ~/files/hashes.txt malicious family_name
177195 \b
178196 """
179197 try :
@@ -193,7 +211,6 @@ def index_by_list(path: str, index_as: str, family_name: str):
193211 click .echo ('Unexpected error occurred, please contact us at support@intezer.com '
194212 f'and attach the log file in { utilities .log_file_path } ' )
195213
196-
197214@main_cli .command ('index' , short_help = 'index a file or a directory' )
198215@click .argument ('path' , type = click .Path (exists = True ))
199216@click .option ('--index-as' , type = click .Choice (['malicious' , 'trusted' ], case_sensitive = True ))
@@ -239,7 +256,7 @@ def index(path: str, index_as: str, family_name: str, ignore_directory_count_lim
239256 f'and attach the log file in { utilities .log_file_path } ' )
240257
241258
242- @main_cli .command ('upload_endpoint_scan ' , short_help = 'upload a directory with offline endpoint scan results' )
259+ @main_cli .command ('upload-endpoint-scan ' , short_help = 'upload a directory with offline endpoint scan results' )
243260@click .argument ('offline_scan_directory' , type = click .Path (exists = True ))
244261@click .option ('--force' , is_flag = True , default = False , help = 'Upload scan even if it was already uploaded' )
245262@click .option ('--max-concurrent' , default = 0 , type = int , help = 'Maximum number of concurrent uploads.' )
@@ -253,7 +270,7 @@ def upload_endpoint_scan(offline_scan_directory: str, force: bool, max_concurren
253270 Examples:
254271 upload a directory with offline endpoint scan results:
255272
256- $ intezer-analyze upload_endpoint_scan /path/to/endpoint_scan_results
273+ $ intezer-analyze upload-endpoint-scan /path/to/endpoint_scan_results
257274 """
258275 try :
259276 create_global_api ()
@@ -267,9 +284,8 @@ def upload_endpoint_scan(offline_scan_directory: str, force: bool, max_concurren
267284 click .echo ('Unexpected error occurred, please contact us at support@intezer.com '
268285 f'and attach the log file in { utilities .log_file_path } ' )
269286
270-
271- @main_cli .command ('upload_endpoint_scans_in_directory' ,
272- short_help = 'upload all subdirectories with offline endpoint scan results' )
287+ @main_cli .command ('upload-endpoint-scans-in-directory' ,
288+ short_help = 'upload all subdirectories with offline endpoint scan results' )
273289@click .argument ('offline_scans_root_directory' , type = click .Path (exists = True ))
274290@click .option ('--force' , is_flag = True , default = False , help = 'Upload scans even if they were already uploaded' )
275291@click .option ('--max-concurrent' , default = 0 , type = int , help = 'Maximum number of concurrent uploads.' )
@@ -283,7 +299,7 @@ def upload_endpoint_scans_in_directory(offline_scans_root_directory: str, force:
283299 Examples:
284300 upload a directory with offline endpoint scan results:
285301
286- $ intezer-analyze upload_endpoint_scans_in_directory /path/to/endpoint_scan_results_root
302+ $ intezer-analyze upload-endpoint-scans-in-directory /path/to/endpoint_scan_results_root
287303 """
288304 try :
289305 create_global_api ()
@@ -297,9 +313,8 @@ def upload_endpoint_scans_in_directory(offline_scans_root_directory: str, force:
297313 click .echo ('Unexpected error occurred, please contact us at support@intezer.com '
298314 f'and attach the log file in { utilities .log_file_path } ' )
299315
300-
301- @main_cli .command ('upload_emails_in_directory' ,
302- short_help = 'upload all subdirectories with .emal files' )
316+ @main_cli .command ('upload-emails-in-directory' ,
317+ short_help = 'upload all subdirectories with .emal files' )
303318@click .argument ('emails_root_directory' , type = click .Path (exists = True , file_okay = False , dir_okay = True ))
304319@click .option ('--ignore-directory-count-limit' ,
305320 is_flag = True ,
@@ -314,7 +329,7 @@ def upload_emails_in_directory(emails_root_directory: str, ignore_directory_coun
314329 Examples:
315330 upload a directory with .eml files:
316331
317- $ intezer-analyze upload_emails_in_directory /path/to/emails_root_directory
332+ $ intezer-analyze upload-emails-in-directory /path/to/emails_root_directory
318333 """
319334 try :
320335 create_global_api ()
@@ -327,11 +342,9 @@ def upload_emails_in_directory(emails_root_directory: str, ignore_directory_coun
327342 click .echo ('Unexpected error occurred, please contact us at support@intezer.com '
328343 f'and attach the log file in { utilities .log_file_path } ' )
329344
330-
331345if __name__ == '__main__' :
332346 try :
333347 main_cli ()
334-
335348 except Exception as e :
336349 logger .exception (f'Unexpected error occurred { e } ' )
337350 click .echo ('Unexpected error occurred' )
0 commit comments