From b6c3022eb2e04467c9882a039b7dc47709f56a41 Mon Sep 17 00:00:00 2001 From: Hang Lei Date: Mon, 16 Jan 2023 17:41:17 +0800 Subject: [PATCH 1/2] Disable recommendation in autocomplete mode --- src/azure-cli-core/azure/cli/core/command_recommender.py | 5 +++++ src/azure-cli-core/azure/cli/core/util.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/azure-cli-core/azure/cli/core/command_recommender.py b/src/azure-cli-core/azure/cli/core/command_recommender.py index 4fa94084db1..57b8e30c145 100644 --- a/src/azure-cli-core/azure/cli/core/command_recommender.py +++ b/src/azure-cli-core/azure/cli/core/command_recommender.py @@ -338,12 +338,14 @@ def _disable_aladdin_service(self): 1. CLI context is missing 2. In air-gapped clouds 3. In testing environments + 4. In autocomplete mode :return: whether Aladdin service need to be disabled or not :type: bool """ from azure.cli.core.cloud import CLOUDS_FORBIDDING_ALADDIN_REQUEST + from azure.cli.core.util import is_autocomplete # CLI is not started well if not self.cli_ctx or not self.cli_ctx.cloud: @@ -357,6 +359,9 @@ def _disable_aladdin_service(self): if self.cli_ctx.__class__.__name__ == 'DummyCli': return True + if is_autocomplete(): + return True + return False def _normalize_parameters(self, args): diff --git a/src/azure-cli-core/azure/cli/core/util.py b/src/azure-cli-core/azure/cli/core/util.py index 9ff0a5136c5..d39527e2965 100644 --- a/src/azure-cli-core/azure/cli/core/util.py +++ b/src/azure-cli-core/azure/cli/core/util.py @@ -1360,3 +1360,9 @@ def should_encrypt_token_cache(cli_ctx): encrypt = cli_ctx.config.getboolean('core', 'encrypt_token_cache', fallback=fallback) return encrypt + + +def is_autocomplete(): + """Detect if the command is running in autocomplete mode""" + from knack.completion import ARGCOMPLETE_ENV_NAME + return os.environ.get(ARGCOMPLETE_ENV_NAME) is not None From 814841f6d79e3a906f93fdb7393b26ad0e7df418 Mon Sep 17 00:00:00 2001 From: Hang Lei Date: Tue, 31 Jan 2023 16:51:17 +0800 Subject: [PATCH 2/2] Remove is_autocomplete --- src/azure-cli-core/azure/cli/core/command_recommender.py | 3 +-- src/azure-cli-core/azure/cli/core/util.py | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/command_recommender.py b/src/azure-cli-core/azure/cli/core/command_recommender.py index 57b8e30c145..bb4f06e7b5c 100644 --- a/src/azure-cli-core/azure/cli/core/command_recommender.py +++ b/src/azure-cli-core/azure/cli/core/command_recommender.py @@ -345,7 +345,6 @@ def _disable_aladdin_service(self): """ from azure.cli.core.cloud import CLOUDS_FORBIDDING_ALADDIN_REQUEST - from azure.cli.core.util import is_autocomplete # CLI is not started well if not self.cli_ctx or not self.cli_ctx.cloud: @@ -359,7 +358,7 @@ def _disable_aladdin_service(self): if self.cli_ctx.__class__.__name__ == 'DummyCli': return True - if is_autocomplete(): + if self.cli_ctx.data['completer_active']: return True return False diff --git a/src/azure-cli-core/azure/cli/core/util.py b/src/azure-cli-core/azure/cli/core/util.py index d39527e2965..9ff0a5136c5 100644 --- a/src/azure-cli-core/azure/cli/core/util.py +++ b/src/azure-cli-core/azure/cli/core/util.py @@ -1360,9 +1360,3 @@ def should_encrypt_token_cache(cli_ctx): encrypt = cli_ctx.config.getboolean('core', 'encrypt_token_cache', fallback=fallback) return encrypt - - -def is_autocomplete(): - """Detect if the command is running in autocomplete mode""" - from knack.completion import ARGCOMPLETE_ENV_NAME - return os.environ.get(ARGCOMPLETE_ENV_NAME) is not None