Skip to content

Conversation

@bebound
Copy link
Contributor

@bebound bebound commented Jan 17, 2023

Description

If the command is not complete, you will get recommendation.
For example, run az account you get

the following arguments are required: _subcommand

Examples from AI knowledge base:
az account list
Get a list of subscriptions for the logged in account. (autogenerated)

az account show
Get the details of a subscription. (autogenerated)

az account set --subscription mysubscription
Set a subscription to be the current active subscription. (autogenerated)

https://docs.microsoft.com/en-US/cli/azure/account#az_account_list
Read more about the command in reference docs

In autocomplete mode, it's common that the command is not complete. The recommendation is useless and time-consuming.
So I disable it in autocomplete mode.

Testing Guide

time IFS=$'\013' _ARC_DEBUG=1 COMP_LINE='az account' COMP_POINT=11 COMP_TYPE="" _ARGCOMPLETE=1 _ARGCOMPLETE_SUPPRESS_SPACE=0 az 8>&1 1>&1 2>&1 9>&1 takes 0.4s.
After applying this PR, it only takes 0.2s.


This checklist is used to make sure that common guidelines for a pull request are followed.

@ghost ghost added Auto-Assign Auto assign by bot Core CLI core infrastructure labels Jan 17, 2023
@ghost ghost requested a review from yonzhan January 17, 2023 08:07
@ghost ghost assigned jiasli Jan 17, 2023
@ghost ghost added this to the Jan 2023 (2023-02-07) milestone Jan 17, 2023
@ghost ghost assigned kairu-ms Jan 17, 2023
@bebound bebound mentioned this pull request Jan 17, 2023
6 tasks
@yonzhan
Copy link
Collaborator

yonzhan commented Jan 17, 2023

Core

kairu-ms
kairu-ms previously approved these changes Jan 30, 2023
@kairu-ms kairu-ms assigned bebound and unassigned kairu-ms Jan 30, 2023
Comment on lines 1365 to 1368
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have similar logic:

self.data['completer_active'] = ARGCOMPLETE_ENV_NAME in os.environ

Comment on lines 362 to 363
if is_autocomplete():
return True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be retrieved from self.cli_ctx.data['completer_active'].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I'll update #24765 too.

@bebound bebound merged commit a39d70b into Azure:dev Feb 1, 2023
@bebound bebound deleted the disable-recommender branch February 1, 2023 08:21
avgale pushed a commit to avgale/azure-cli that referenced this pull request Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot Core CLI core infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants