diff --git a/HISTORY.rst b/HISTORY.rst index fa01800d..f19ed81a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,11 @@ Release History =============== +0.1.73 +++++++ +* `azdev command-change meta-export`: Add `has_completer` to denote whether completer is configed in arg +* `azdev command-change meta-export`: Extracting arg help and example for loaded HelpFiles + 0.1.72 ++++++ * Bump `pylint` to 3 diff --git a/azdev/__init__.py b/azdev/__init__.py index 44567cd8..055031cd 100644 --- a/azdev/__init__.py +++ b/azdev/__init__.py @@ -4,4 +4,4 @@ # license information. # ----------------------------------------------------------------------------- -__VERSION__ = '0.1.72' +__VERSION__ = '0.1.73' diff --git a/azdev/operations/command_change/__init__.py b/azdev/operations/command_change/__init__.py index 07d14041..683397f4 100644 --- a/azdev/operations/command_change/__init__.py +++ b/azdev/operations/command_change/__init__.py @@ -4,7 +4,7 @@ # license information. # ----------------------------------------------------------------------------- -# pylint: disable=no-else-return, too-many-nested-blocks +# pylint: disable=no-else-return, too-many-nested-blocks, too-many-locals, too-many-branches import time @@ -72,6 +72,16 @@ def export_command_meta(modules=None, git_source=None, git_target=None, git_repo display('Commands loaded in {} sec'.format(stop - start)) command_loader = az_cli.invocation.commands_loader + from azure.cli.core.file_util import get_all_help + + help_info = {} + if with_help or with_example: + help_files = get_all_help(az_cli) + for help_item in help_files: + if not help_item.command: + continue + help_info[help_item.command] = help_item + # trim command table to selected_modules command_loader = filter_modules(command_loader, modules=selected_mod_names) @@ -85,7 +95,7 @@ def export_command_meta(modules=None, git_source=None, git_target=None, git_repo "name": command_name, "source": _get_command_source(command_name, command), "is_aaz": False, - "help": command.help, + "help": help_info[command_name] if command_name in help_info else None, "confirmation": command.confirmation is True, "arguments": [], "az_arguments_schema": None, diff --git a/azdev/operations/command_change/custom.py b/azdev/operations/command_change/custom.py index dfa91c06..72381006 100644 --- a/azdev/operations/command_change/custom.py +++ b/azdev/operations/command_change/custom.py @@ -119,6 +119,15 @@ def normalize_para_type(type_opts, value): normalize_para_type(type_bool_opts, "bool") +def get_command_examples(command_info, command_meta): + example_items = [] + if command_info and command_info.get("help", None) and hasattr(command_info["help"], "examples"): + for example_obj in command_info["help"].examples: + example_items.append({"name": example_obj.name, "text": example_obj.text}) + if example_items: + command_meta["examples"] = example_items + + def gen_command_meta(command_info, with_help=False, with_example=False): stored_property_when_exist = ["confirmation", "supports_no_wait", "is_preview", "deprecate_info"] command_meta = { @@ -129,15 +138,10 @@ def gen_command_meta(command_info, with_help=False, with_example=False): if command_info.get(prop, None): command_meta[prop] = command_info[prop] if with_example: - try: - command_meta["examples"] = command_info["help"]["examples"] - except AttributeError: - pass + get_command_examples(command_info, command_meta) if with_help: - try: - command_meta["desc"] = command_info["help"]["short-summary"] - except AttributeError: - pass + if command_info.get("help", None) and hasattr(command_info["help"], "short_summary"): + command_meta["desc"] = command_info["help"].short_summary parameters = [] for _, argument in command_info["arguments"].items(): if argument.type is None: @@ -163,13 +167,15 @@ def gen_command_meta(command_info, with_help=False, with_example=False): para["id_part"] = settings["id_part"] if settings.get("nargs", None): para["nargs"] = settings["nargs"] + if settings.get("completer", None): + para["has_completer"] = True if settings.get("default", None): if not isinstance(settings["default"], (float, int, str, list, bool)): para["default"] = str(settings["default"]) else: para["default"] = settings["default"] if with_help: - para["desc"] = settings["help"] + para["desc"] = settings.get("help", "") if command_info["is_aaz"] and command_info["az_arguments_schema"]: process_aaz_argument(command_info["az_arguments_schema"], settings, para) normalize_para_types(para)