-
Notifications
You must be signed in to change notification settings - Fork 218
prompt: case-insensitive sorting for subscriptions #4969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
cli/azd/pkg/prompt/prompter.go
Outdated
@@ -218,6 +219,10 @@ func (p *DefaultPrompter) getSubscriptionOptions(ctx context.Context) ([]string, | |||
return nil, nil, nil, fmt.Errorf("listing accounts: %w", err) | |||
} | |||
|
|||
sort.Slice(subscriptionInfos, func(i, j int) bool { | |||
return strings.ToLower(subscriptionInfos[i].Name) < strings.ToLower(subscriptionInfos[j].Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calls to strings.ToLower
here ends up allocating 2x string copies for each element.
A way to avoid string allocations is to leverage slices and lowercasing each character rune. This kind of string comparison doesn't work for all languages -- but it would work for ASCII usage.
bc29144
to
105b26c
Compare
@@ -157,7 +157,7 @@ func (p *DefaultPrompter) PromptResourceGroupFrom( | |||
} | |||
|
|||
slices.SortFunc(groups, func(a, b *azapi.Resource) int { | |||
return strings.Compare(a.Name, b.Name) | |||
return stringutil.CompareLower(a.Name, b.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vhvb1989 , @JeffreyCA made a really good point on the linked issue that resource groups should behave similarly.
I suspect it goes beyond just these resources, so I added a new comparison function that avoids string allocations (previous implementation used strings.ToLower
which creates a new string copy per each element iteration), if we wanted to do this more generally.
However, I'm truly wondering if we're down the right track here. There are many different Azure resources that will likely encounter the same problem, and I'm not sure if we'll want to apply this rule consistently.
Does the case-insensitive comparison truly feel any better? Presentation-wise it can get look a little messy at times with mixed capitalization. Curious what everyone thinks here -- My position shifted to slightly against this after looking at it more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as the output is deterministic, I don't have any strong opinion about the sorting details.
Similar prompts are: Key vault Accounts and Secrets (or maybe not due to naming-rules for key vault), AI Models listing, AI Projects listing, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't have any objections with just an easy normalized to lower based sorting instead of something more complex considering any lists we show are relatively small (< 100 items).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me yes it feels a little more natural than listing names starting with A-Z followed by a-z. I found this resource naming doc, which I don't know if it's helpful. Most names seem to be case-sensitive, but it varies quite a bit whether uppercase letters are permitted in the name
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash:
pwsh:
WindowsPowerShell install
MSI install
Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
105b26c
Apply case-insensitive sorting at the subscription prompt display
Fixes #4961