Skip to content

Commit a47ecc1

Browse files
authored
[Interactive] Updates for command table dump (#5283)
* Fixes #5278. * Improve performance of az interactive dump_command_table
1 parent a33a176 commit a47ecc1

File tree

2 files changed

+16
-37
lines changed

2 files changed

+16
-37
lines changed

src/command_modules/azure-cli-backup/azure/cli/command_modules/backup/custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def _should_use_original_storage_account(recovery_point, restore_to_staging_stor
309309
# RP doesn't support OSA.
310310
raise CLIError(
311311
"""
312-
This recovery point doesnt have the capability to restore disks to their original storage
312+
This recovery point doesn't have the capability to restore disks to their original storage
313313
accounts. The disks and the VM config file will be uploaded to the given storage account.
314314
""")
315315
return use_original_storage_account

src/command_modules/azure-cli-interactive/azclishell/_dump_commands.py

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,6 @@ def __init__(self, shell_ctx):
2626
self.command_table = None
2727
self.shell_ctx = shell_ctx
2828

29-
def install_modules(self):
30-
installed_command_modules = []
31-
for cmd in self.command_table:
32-
try:
33-
self.command_table[cmd].load_arguments()
34-
except (ImportError, ValueError):
35-
pass
36-
mods_ns_pkg = import_module('azure.cli.command_modules')
37-
for _, modname, _ in pkgutil.iter_modules(mods_ns_pkg.__path__):
38-
if modname not in BLACKLISTED_MODS:
39-
installed_command_modules.append(modname)
40-
41-
for mod in installed_command_modules:
42-
try:
43-
mod = import_module('azure.cli.command_modules.' + mod)
44-
mod.load_params(mod)
45-
mod.load_commands()
46-
47-
except Exception: # pylint: disable=broad-except
48-
# print("Error loading: {}".format(mod))
49-
pass
50-
self.shell_ctx.cli_ctx.invocation.commands_loader.load_arguments(None)
51-
5229
def load_help_files(self, data):
5330
""" loads all the extra information from help files """
5431
for cmd in helps:
@@ -95,38 +72,36 @@ def load_help_files(self, data):
9572
def dump_command_table(self, shell_ctx):
9673
""" dumps the command table """
9774

98-
self.command_table = shell_ctx.cli_ctx.invocation.commands_loader.command_table
99-
command_file = shell_ctx.config.get_help_files()
100-
101-
self.install_modules()
102-
add_id_parameters(self.command_table)
75+
loader = shell_ctx.cli_ctx.invocation.commands_loader
76+
cmd_table = loader.load_command_table(None)
77+
loader.load_arguments('')
10378

10479
data = {}
105-
for cmd in self.command_table:
80+
for cmd in cmd_table:
10681
com_descrip = {} # commands to their descriptions, examples, and parameter info
10782
param_descrip = {} # parameters to their aliases, required, and descriptions
10883

10984
try:
110-
command_description = self.command_table[cmd].description
85+
command_description = cmd_table[cmd].description
11186
if callable(command_description):
11287
command_description = command_description()
11388

11489
com_descrip['help'] = command_description
11590
com_descrip['examples'] = ""
11691

11792
# checking all the parameters for a single command
118-
for key in self.command_table[cmd].arguments:
93+
for key in cmd_table[cmd].arguments:
11994
required = ""
12095
help_desc = ""
12196

122-
if self.command_table[cmd].arguments[key].type.settings.get('required'):
97+
if cmd_table[cmd].arguments[key].type.settings.get('required'):
12398
required = "[REQUIRED]"
124-
if self.command_table[cmd].arguments[key].type.settings.get('help'):
125-
help_desc = self.command_table[cmd].arguments[key].type.settings.get('help')
99+
if cmd_table[cmd].arguments[key].type.settings.get('help'):
100+
help_desc = cmd_table[cmd].arguments[key].type.settings.get('help')
126101

127102
# checking aliasing
128103
name_options = []
129-
for name in self.command_table[cmd].arguments[key].options_list:
104+
for name in cmd_table[cmd].arguments[key].options_list:
130105
name_options.append(name)
131106

132107
options = {
@@ -135,16 +110,20 @@ def dump_command_table(self, shell_ctx):
135110
'help': help_desc
136111
}
137112
# the key is the first alias option
138-
param_descrip[self.command_table[cmd].arguments[key].options_list[0]] = options
113+
param_descrip[cmd_table[cmd].arguments[key].options_list[0]] = options
139114

140115
com_descrip['parameters'] = param_descrip
141116
data[cmd] = com_descrip
142117
except (ImportError, ValueError):
143118
pass
144119

120+
add_id_parameters(cmd_table)
145121
self.load_help_files(data)
146122

123+
self.command_table = cmd_table
124+
147125
# dump into the cache file
126+
command_file = shell_ctx.config.get_help_files()
148127
with open(os.path.join(get_cache_dir(shell_ctx), command_file), 'w') as help_file:
149128
json.dump(data, help_file)
150129

0 commit comments

Comments
 (0)