From 7d11c4960fe7e5e97a3ffaa07c0f5e0c814ffcbc Mon Sep 17 00:00:00 2001 From: Matthew Booe Date: Mon, 27 Jan 2020 14:11:41 -0800 Subject: [PATCH 1/9] Remove EUII information from az find telemetry --- .../azure/cli/command_modules/find/custom.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/find/custom.py b/src/azure-cli/azure/cli/command_modules/find/custom.py index b9ef45fd55d..74b06280aaf 100644 --- a/src/azure-cli/azure/cli/command_modules/find/custom.py +++ b/src/azure-cli/azure/cli/command_modules/find/custom.py @@ -93,21 +93,9 @@ def should_enable_styling(): def call_aladdin_service(query): - client_request_id = '' - if telemetry_core._session.application: # pylint: disable=protected-access - client_request_id = telemetry_core._session.application.data['headers']['x-ms-client-request-id'] # pylint: disable=protected-access - - session_id = telemetry_core._session._get_base_properties()['Reserved.SessionId'] # pylint: disable=protected-access - subscription_id = telemetry_core._get_azure_subscription_id() # pylint: disable=protected-access - client_request_id = client_request_id # pylint: disable=protected-access - installation_id = telemetry_core._get_installation_id() # pylint: disable=protected-access version = str(parse_version(core_version)) context = { - "sessionId": session_id, - "subscriptionId": subscription_id, - "clientRequestId": client_request_id, - "installationId": installation_id, "versionNumber": version } From a1b71b1d3167107c9afaadf7c727a00d75dfd889 Mon Sep 17 00:00:00 2001 From: Matthew Booe Date: Mon, 2 Mar 2020 15:45:51 -0800 Subject: [PATCH 2/9] Working version of new example replacement --- src/azure-cli-core/azure/cli/core/_help.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/azure-cli-core/azure/cli/core/_help.py b/src/azure-cli-core/azure/cli/core/_help.py index 4037a0e5e2b..9a5dff28155 100644 --- a/src/azure-cli-core/azure/cli/core/_help.py +++ b/src/azure-cli-core/azure/cli/core/_help.py @@ -128,6 +128,8 @@ def __init__(self, cli_ctx): group_help_cls=CliGroupHelpFile, help_cls=CliHelpFile) from knack.help import HelpObject + # Used to specify what the original help request was for + self.original_nouns = '' # TODO: This workaround is used to avoid a bizarre bug in Python 2.7. It # essentially reassigns Knack's HelpObject._normalize_text implementation @@ -150,6 +152,7 @@ def new_normalize_text(s): # override def show_help(self, cli_name, nouns, parser, is_group): self.update_loaders_with_help_file_contents(nouns) + self.original_nouns = ' '.join(nouns) super(AzCliHelp, self).show_help(cli_name, nouns, parser, is_group) print(SURVEY_PROMPT) @@ -195,6 +198,10 @@ def update_loaders_with_help_file_contents(self, nouns): def example_provider(help_file): return help_file.examples + @staticmethod + def replace_examples(examples, command): + return examples + class CliHelpFile(KnackHelpFile): @@ -248,6 +255,10 @@ def load(self, options): for loader in ordered_loaders: loader.versioned_load(self, options) + # Used as a hook for changing the default examples + if self.help_ctx.original_nouns == self.command: + self.examples = AzCliHelp.replace_examples(self.examples, self.command) + class CliGroupHelpFile(KnackGroupHelpFile, CliHelpFile): From e6784f899362a280cf62d6ca912a16e5c3c7ae74 Mon Sep 17 00:00:00 2001 From: Matthew Booe Date: Mon, 2 Mar 2020 16:05:09 -0800 Subject: [PATCH 3/9] Update hook method to be simpler --- src/azure-cli-core/azure/cli/core/_help.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/_help.py b/src/azure-cli-core/azure/cli/core/_help.py index 9a5dff28155..c6829cd94a4 100644 --- a/src/azure-cli-core/azure/cli/core/_help.py +++ b/src/azure-cli-core/azure/cli/core/_help.py @@ -198,9 +198,10 @@ def update_loaders_with_help_file_contents(self, nouns): def example_provider(help_file): return help_file.examples + # This method is meant to be a hook that can be overridden by an extension or module. @staticmethod - def replace_examples(examples, command): - return examples + def check_for_new_examples(command): # pylint: disable=unused-argument + return [] class CliHelpFile(KnackHelpFile): @@ -257,7 +258,9 @@ def load(self, options): # Used as a hook for changing the default examples if self.help_ctx.original_nouns == self.command: - self.examples = AzCliHelp.replace_examples(self.examples, self.command) + new_examples = AzCliHelp.check_for_new_examples(self.command) + if new_examples: + self.examples = new_examples class CliGroupHelpFile(KnackGroupHelpFile, CliHelpFile): From f8ed94ba0721d8bfa930f8e4bf9091b6a071ada3 Mon Sep 17 00:00:00 2001 From: Matthew Booe Date: Tue, 3 Mar 2020 08:54:42 -0800 Subject: [PATCH 4/9] Removed old hook --- src/azure-cli-core/azure/cli/core/_help.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/_help.py b/src/azure-cli-core/azure/cli/core/_help.py index c6829cd94a4..c07fad279eb 100644 --- a/src/azure-cli-core/azure/cli/core/_help.py +++ b/src/azure-cli-core/azure/cli/core/_help.py @@ -78,7 +78,7 @@ def _print_examples(help_file): from colorama import Style indent = 0 _print_indent('Examples', indent) - for e in AzCliHelp.example_provider(help_file): + for e in help_file.examples: indent = 1 _print_indent(u'{0}'.format(e.short_summary), indent) indent = 2 @@ -193,11 +193,6 @@ def update_loaders_with_help_file_contents(self, nouns): file_contents[name] = self._name_to_content[name] self.versioned_loaders[ldr_cls_name].update_file_contents(file_contents) - # This method is meant to be a hook that can be overridden by an extension or module. - @staticmethod - def example_provider(help_file): - return help_file.examples - # This method is meant to be a hook that can be overridden by an extension or module. @staticmethod def check_for_new_examples(command): # pylint: disable=unused-argument From e6a722037450bd3cb72611f71d56b958f62f8126 Mon Sep 17 00:00:00 2001 From: Matthew Booe Date: Tue, 3 Mar 2020 09:14:16 -0800 Subject: [PATCH 5/9] Style fix --- src/azure-cli-core/azure/cli/core/_help.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/_help.py b/src/azure-cli-core/azure/cli/core/_help.py index c07fad279eb..123d611a1f0 100644 --- a/src/azure-cli-core/azure/cli/core/_help.py +++ b/src/azure-cli-core/azure/cli/core/_help.py @@ -195,7 +195,7 @@ def update_loaders_with_help_file_contents(self, nouns): # This method is meant to be a hook that can be overridden by an extension or module. @staticmethod - def check_for_new_examples(command): # pylint: disable=unused-argument + def check_for_new_examples(command): # pylint: disable=unused-argument return [] From ac226a040af309f457fe23823db27d1f0392d9b1 Mon Sep 17 00:00:00 2001 From: Matthew Booe Date: Wed, 4 Mar 2020 09:49:00 -0800 Subject: [PATCH 6/9] Update the hook to take and use the built in examples --- src/azure-cli-core/azure/cli/core/_help.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/_help.py b/src/azure-cli-core/azure/cli/core/_help.py index 123d611a1f0..e863eded139 100644 --- a/src/azure-cli-core/azure/cli/core/_help.py +++ b/src/azure-cli-core/azure/cli/core/_help.py @@ -195,8 +195,8 @@ def update_loaders_with_help_file_contents(self, nouns): # This method is meant to be a hook that can be overridden by an extension or module. @staticmethod - def check_for_new_examples(command): # pylint: disable=unused-argument - return [] + def check_for_new_examples(command, examples): # pylint: disable=unused-argument + return examples class CliHelpFile(KnackHelpFile): @@ -253,9 +253,7 @@ def load(self, options): # Used as a hook for changing the default examples if self.help_ctx.original_nouns == self.command: - new_examples = AzCliHelp.check_for_new_examples(self.command) - if new_examples: - self.examples = new_examples + self.examples = AzCliHelp.check_for_new_examples(self.command, self.examples) class CliGroupHelpFile(KnackGroupHelpFile, CliHelpFile): From eabdcbb91f01eda71e927cb546d3727c41e8cf32 Mon Sep 17 00:00:00 2001 From: Matthew Booe Date: Wed, 4 Mar 2020 10:20:55 -0800 Subject: [PATCH 7/9] Switch to custom implementation of `show_help` --- src/azure-cli-core/azure/cli/core/_help.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/_help.py b/src/azure-cli-core/azure/cli/core/_help.py index e863eded139..c67eebf7b83 100644 --- a/src/azure-cli-core/azure/cli/core/_help.py +++ b/src/azure-cli-core/azure/cli/core/_help.py @@ -128,8 +128,6 @@ def __init__(self, cli_ctx): group_help_cls=CliGroupHelpFile, help_cls=CliHelpFile) from knack.help import HelpObject - # Used to specify what the original help request was for - self.original_nouns = '' # TODO: This workaround is used to avoid a bizarre bug in Python 2.7. It # essentially reassigns Knack's HelpObject._normalize_text implementation @@ -149,11 +147,21 @@ def new_normalize_text(s): self._register_help_loaders() self._name_to_content = {} - # override def show_help(self, cli_name, nouns, parser, is_group): self.update_loaders_with_help_file_contents(nouns) - self.original_nouns = ' '.join(nouns) - super(AzCliHelp, self).show_help(cli_name, nouns, parser, is_group) + + import colorama + colorama.init(autoreset=True) + delimiters = ' '.join(nouns) + help_file = self.command_help_cls(self, delimiters, parser) if not is_group \ + else self.group_help_cls(self, delimiters, parser) + help_file.load(parser) + if not nouns: + help_file.command = '' + else: + help_file.examples = AzCliHelp.check_for_new_examples(help_file.command, help_file.examples) + self._print_detailed_help(cli_name, help_file) + print(SURVEY_PROMPT) def _register_help_loaders(self): @@ -251,10 +259,6 @@ def load(self, options): for loader in ordered_loaders: loader.versioned_load(self, options) - # Used as a hook for changing the default examples - if self.help_ctx.original_nouns == self.command: - self.examples = AzCliHelp.check_for_new_examples(self.command, self.examples) - class CliGroupHelpFile(KnackGroupHelpFile, CliHelpFile): From c3dae5e9d556b8882a4678b5088b71efea5fe30c Mon Sep 17 00:00:00 2001 From: Matthew Booe Date: Thu, 5 Mar 2020 17:01:32 -0800 Subject: [PATCH 8/9] Better signature --- src/azure-cli-core/azure/cli/core/_help.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/_help.py b/src/azure-cli-core/azure/cli/core/_help.py index c67eebf7b83..8763df9c77f 100644 --- a/src/azure-cli-core/azure/cli/core/_help.py +++ b/src/azure-cli-core/azure/cli/core/_help.py @@ -159,7 +159,7 @@ def show_help(self, cli_name, nouns, parser, is_group): if not nouns: help_file.command = '' else: - help_file.examples = AzCliHelp.check_for_new_examples(help_file.command, help_file.examples) + help_file.examples = AzCliHelp.update_examples(help_file) self._print_detailed_help(cli_name, help_file) print(SURVEY_PROMPT) @@ -203,8 +203,8 @@ def update_loaders_with_help_file_contents(self, nouns): # This method is meant to be a hook that can be overridden by an extension or module. @staticmethod - def check_for_new_examples(command, examples): # pylint: disable=unused-argument - return examples + def update_examples(help_file): + return help_file.examples class CliHelpFile(KnackHelpFile): From af720480f309fbab9af3d808633d9dd94fac428a Mon Sep 17 00:00:00 2001 From: Matthew Booe Date: Thu, 5 Mar 2020 17:18:45 -0800 Subject: [PATCH 9/9] Update by reference --- src/azure-cli-core/azure/cli/core/_help.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/_help.py b/src/azure-cli-core/azure/cli/core/_help.py index 8763df9c77f..500dbeebafb 100644 --- a/src/azure-cli-core/azure/cli/core/_help.py +++ b/src/azure-cli-core/azure/cli/core/_help.py @@ -159,7 +159,7 @@ def show_help(self, cli_name, nouns, parser, is_group): if not nouns: help_file.command = '' else: - help_file.examples = AzCliHelp.update_examples(help_file) + AzCliHelp.update_examples(help_file) self._print_detailed_help(cli_name, help_file) print(SURVEY_PROMPT) @@ -204,7 +204,7 @@ def update_loaders_with_help_file_contents(self, nouns): # This method is meant to be a hook that can be overridden by an extension or module. @staticmethod def update_examples(help_file): - return help_file.examples + pass class CliHelpFile(KnackHelpFile):