Skip to content

Commit 4f5a0b6

Browse files
authored
Fix cmd help extracting and add has_completer in command-change meta-export (#461)
* add completer * set help and example from helpfiles
1 parent db1212a commit 4f5a0b6

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
33
Release History
44
===============
5+
0.1.73
6+
++++++
7+
* `azdev command-change meta-export`: Add `has_completer` to denote whether completer is configed in arg
8+
* `azdev command-change meta-export`: Extracting arg help and example for loaded HelpFiles
9+
510
0.1.72
611
++++++
712
* Bump `pylint` to 3

azdev/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# license information.
55
# -----------------------------------------------------------------------------
66

7-
__VERSION__ = '0.1.72'
7+
__VERSION__ = '0.1.73'

azdev/operations/command_change/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# license information.
55
# -----------------------------------------------------------------------------
66

7-
# pylint: disable=no-else-return, too-many-nested-blocks
7+
# pylint: disable=no-else-return, too-many-nested-blocks, too-many-locals, too-many-branches
88

99
import time
1010

@@ -72,6 +72,16 @@ def export_command_meta(modules=None, git_source=None, git_target=None, git_repo
7272
display('Commands loaded in {} sec'.format(stop - start))
7373
command_loader = az_cli.invocation.commands_loader
7474

75+
from azure.cli.core.file_util import get_all_help
76+
77+
help_info = {}
78+
if with_help or with_example:
79+
help_files = get_all_help(az_cli)
80+
for help_item in help_files:
81+
if not help_item.command:
82+
continue
83+
help_info[help_item.command] = help_item
84+
7585
# trim command table to selected_modules
7686
command_loader = filter_modules(command_loader, modules=selected_mod_names)
7787

@@ -85,7 +95,7 @@ def export_command_meta(modules=None, git_source=None, git_target=None, git_repo
8595
"name": command_name,
8696
"source": _get_command_source(command_name, command),
8797
"is_aaz": False,
88-
"help": command.help,
98+
"help": help_info[command_name] if command_name in help_info else None,
8999
"confirmation": command.confirmation is True,
90100
"arguments": [],
91101
"az_arguments_schema": None,

azdev/operations/command_change/custom.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ def normalize_para_type(type_opts, value):
119119
normalize_para_type(type_bool_opts, "bool")
120120

121121

122+
def get_command_examples(command_info, command_meta):
123+
example_items = []
124+
if command_info and command_info.get("help", None) and hasattr(command_info["help"], "examples"):
125+
for example_obj in command_info["help"].examples:
126+
example_items.append({"name": example_obj.name, "text": example_obj.text})
127+
if example_items:
128+
command_meta["examples"] = example_items
129+
130+
122131
def gen_command_meta(command_info, with_help=False, with_example=False):
123132
stored_property_when_exist = ["confirmation", "supports_no_wait", "is_preview", "deprecate_info"]
124133
command_meta = {
@@ -129,15 +138,10 @@ def gen_command_meta(command_info, with_help=False, with_example=False):
129138
if command_info.get(prop, None):
130139
command_meta[prop] = command_info[prop]
131140
if with_example:
132-
try:
133-
command_meta["examples"] = command_info["help"]["examples"]
134-
except AttributeError:
135-
pass
141+
get_command_examples(command_info, command_meta)
136142
if with_help:
137-
try:
138-
command_meta["desc"] = command_info["help"]["short-summary"]
139-
except AttributeError:
140-
pass
143+
if command_info.get("help", None) and hasattr(command_info["help"], "short_summary"):
144+
command_meta["desc"] = command_info["help"].short_summary
141145
parameters = []
142146
for _, argument in command_info["arguments"].items():
143147
if argument.type is None:
@@ -163,13 +167,15 @@ def gen_command_meta(command_info, with_help=False, with_example=False):
163167
para["id_part"] = settings["id_part"]
164168
if settings.get("nargs", None):
165169
para["nargs"] = settings["nargs"]
170+
if settings.get("completer", None):
171+
para["has_completer"] = True
166172
if settings.get("default", None):
167173
if not isinstance(settings["default"], (float, int, str, list, bool)):
168174
para["default"] = str(settings["default"])
169175
else:
170176
para["default"] = settings["default"]
171177
if with_help:
172-
para["desc"] = settings["help"]
178+
para["desc"] = settings.get("help", "")
173179
if command_info["is_aaz"] and command_info["az_arguments_schema"]:
174180
process_aaz_argument(command_info["az_arguments_schema"], settings, para)
175181
normalize_para_types(para)

0 commit comments

Comments
 (0)