-
Notifications
You must be signed in to change notification settings - Fork 264
rework template list in 'azd init' for usability #6264
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import ( | |
| "strings" | ||
|
|
||
| "github.com/azure/azure-dev/cli/azd/pkg/input" | ||
| "github.com/azure/azure-dev/cli/azd/pkg/output" | ||
| ) | ||
|
|
||
| var ( | ||
|
|
@@ -196,47 +197,41 @@ func PromptTemplate( | |
| return Template{}, fmt.Errorf("prompting for template: %w", err) | ||
| } | ||
|
|
||
| templateChoices := []*Template{} | ||
| duplicateNames := []string{} | ||
|
|
||
| // Check for duplicate template names | ||
| for _, template := range templates { | ||
| hasDuplicateName := slices.ContainsFunc(templateChoices, func(t *Template) bool { | ||
| return t.Name == template.Name | ||
| }) | ||
| slices.SortFunc(templates, func(a, b *Template) int { | ||
| return strings.Compare(a.Name, b.Name) | ||
| }) | ||
|
|
||
| if hasDuplicateName { | ||
| duplicateNames = append(duplicateNames, template.Name) | ||
| choices := make([]string, 0, len(templates)+1) | ||
| for i, template := range templates { | ||
| choice := template.Name | ||
| if len(choice) > 70 { | ||
| choice = choice[0:67] + "..." | ||
| } | ||
|
|
||
| templateChoices = append(templateChoices, template) | ||
| } | ||
|
|
||
| templateNames := make([]string, 0, len(templates)+1) | ||
| templateDetails := make([]string, 0, len(templates)+1) | ||
|
|
||
| for _, template := range templates { | ||
| templateChoice := template.Name | ||
|
|
||
| // Disambiguate duplicate template names with source identifier | ||
| if slices.Contains(duplicateNames, template.Name) { | ||
| templateChoice += fmt.Sprintf(" (%s)", template.Source) | ||
| for j, otherTemplate := range templates { | ||
| if i != j && strings.EqualFold(template.Name, otherTemplate.Name) { | ||
| // Disambiguate duplicate template names with source identifier | ||
| choice += fmt.Sprintf(" (%s)", template.Source) | ||
| } | ||
| } | ||
|
|
||
| templateDetails = append(templateDetails, template.RepositoryPath) | ||
| languages := template.DisplayLanguages() | ||
| path := template.CanonicalPath() | ||
|
|
||
| if slices.Contains(templateNames, templateChoice) { | ||
| duplicateNames = append(duplicateNames, templateChoice) | ||
| } | ||
| choices = append(choices, fmt.Sprintf("%s\t%s\t[%s]", | ||
| choice, | ||
| path, | ||
| strings.Join(languages, ","))) | ||
| } | ||
|
Comment on lines
+221
to
+225
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this design is going to cause lots of line wrapping due to template names + URLs + languages unless user is running in a very wide terminal window.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| templateNames = append(templateNames, templateChoice) | ||
| choices, err = output.TabAlign(choices, 3) | ||
| if err != nil { | ||
| return Template{}, fmt.Errorf("aligning choices: %w", err) | ||
| } | ||
|
|
||
| selected, err := console.Select(ctx, input.ConsoleOptions{ | ||
| Message: message, | ||
| Options: templateNames, | ||
| OptionDetails: templateDetails, | ||
| DefaultValue: templateNames[0], | ||
| Message: message, | ||
| Options: choices, | ||
| }) | ||
|
|
||
| // separate this prompt from the next log | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.