99
1010from knack .log import get_logger
1111
12- from azdev .utilities import COMMAND_MODULE_PREFIX
12+ from azdev .utilities import get_name_index
1313
1414
1515logger = get_logger (__name__ )
1818_LOADER_CLS_RE = re .compile ('.*azure/cli/command_modules/(?P<module>[^/]*)/__init__.*' )
1919
2020
21- def filter_modules (command_loader , help_file_entries , modules = None ):
21+ def filter_modules (command_loader , help_file_entries , modules = None , include_whl_extensions = False ):
2222 """ Modify the command table and help entries to only include certain modules/extensions.
2323
2424 : param command_loader: The CLICommandsLoader containing the command table to filter.
2525 : help_file_entries: The dict of HelpFile entries to filter.
2626 : modules: [str] list of module or extension names to retain.
2727 """
28- return _filter_mods (command_loader , help_file_entries , modules = modules )
28+ return _filter_mods (command_loader , help_file_entries , modules = modules ,
29+ include_whl_extensions = include_whl_extensions )
2930
3031
31- def exclude_commands (command_loader , help_file_entries , module_exclusions ):
32+ def exclude_commands (command_loader , help_file_entries , module_exclusions , include_whl_extensions = False ):
3233 """ Modify the command table and help entries to exclude certain modules/extensions.
3334
3435 : param command_loader: The CLICommandsLoader containing the command table to filter.
3536 : help_file_entries: The dict of HelpFile entries to filter.
3637 : modules: [str] list of module or extension names to remove.
3738 """
38- return _filter_mods (command_loader , help_file_entries , modules = module_exclusions , exclude = True )
39+ return _filter_mods (command_loader , help_file_entries , modules = module_exclusions , exclude = True ,
40+ include_whl_extensions = include_whl_extensions )
3941
4042
41- def _filter_mods (command_loader , help_file_entries , modules = None , exclude = False ):
43+ def _filter_mods (command_loader , help_file_entries , modules = None , exclude = False , include_whl_extensions = False ):
4244 modules = modules or []
43- modules = [x .replace (COMMAND_MODULE_PREFIX , '' ) for x in modules ]
4445
4546 # command tables and help entries must be copied to allow for seperate linter scope
4647 command_table = command_loader .command_table .copy ()
@@ -49,6 +50,7 @@ def _filter_mods(command_loader, help_file_entries, modules=None, exclude=False)
4950 command_loader .command_table = command_table
5051 command_loader .command_group_table = command_group_table
5152 help_file_entries = help_file_entries .copy ()
53+ name_index = get_name_index (include_whl_extensions = include_whl_extensions )
5254
5355 for command_name in list (command_loader .command_table .keys ()):
5456 try :
@@ -58,7 +60,11 @@ def _filter_mods(command_loader, help_file_entries, modules=None, exclude=False)
5860 logger .warning (ex )
5961 source_name = None
6062
61- is_specified = source_name in modules
63+ try :
64+ long_name = name_index [source_name ]
65+ is_specified = source_name in modules or long_name in modules
66+ except KeyError :
67+ is_specified = False
6268 if is_specified == exclude :
6369 # brute force method of ignoring commands from a module or extension
6470 command_loader .command_table .pop (command_name , None )
0 commit comments