Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 213
Improve experience for multiple builtin templates#1052
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5278af1
Improve support for multiple builtin templates
lennartkats-db acc1347
Merge branch 'main' into multi-init
lennartkats-db 9c1e872
Merge branch 'main' into multi-init
lennartkats-db 19ffb63
Merge branch 'main' into multi-init
lennartkats-db 354c642
Use a const
lennartkats-db 0bdab02
Merge branch 'multi-init' of github.com:lennartkats-db/cli into multi…
lennartkats-db d58811f
Process feedback
lennartkats-db d01eaf4
Clarify name
lennartkats-db a1464c4
Merge branch 'main' into multi-init
lennartkats-db 885efa6
Update libs/cmdio/io.go
lennartkats-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -155,19 +155,13 @@ func RenderReader(ctx context.Context, r io.Reader) error { | ||
| } | ||
| } | ||
| type tuple struct{ Name, Id string } | ||
| type Tuple struct{ Name, Id string } | ||
| func (c *cmdIO) Select(names map[string]string, label string) (id string, err error) { | ||
| func (c *cmdIO) Select(items []Tuple, label string) (id string, err error) { | ||
| if !c.interactive { | ||
| return "", fmt.Errorf("expected to have %s", label) | ||
| } | ||
| var items []tuple | ||
| for k, v := range names { | ||
| items = append(items, tuple{k, v}) | ||
| } | ||
| slices.SortFunc(items, func(a, b tuple) int { | ||
| return strings.Compare(a.Name, b.Name) | ||
| }) | ||
| idx, _, err := (&promptui.Select{ | ||
| Label: label, | ||
| Items: items, | ||
| @@ -190,13 +184,25 @@ func (c *cmdIO) Select(names map[string]string, label string) (id string, err er | ||
| return | ||
| } | ||
| // Show a selection prompt where the user can pick one of the name/id items. | ||
| // The items are sorted alphabetically by name. | ||
| func Select[V any](ctx context.Context, names map[string]V, label string) (id string, err error) { | ||
| c := fromContext(ctx) | ||
| stringNames := map[string]string{} | ||
| var items []Tuple | ||
| for k, v := range names { | ||
| stringNames[k] = fmt.Sprint(v) | ||
| items = append(items, Tuple{k, fmt.Sprint(v)}) | ||
| } | ||
| return c.Select(stringNames, label) | ||
| slices.SortFunc(items, func(a, b Tuple) int { | ||
| return strings.Compare(a.Name, b.Name) | ||
| }) | ||
| return c.Select(items, label) | ||
| } | ||
| // Show a selection prompt where the user can pick one of the name/id items. | ||
| // The items appear in the order specified in the "items" argument. | ||
| func SelectOrdered(ctx context.Context, items []Tuple, label string) (id string, err error) { | ||
lennartkats-db marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| c := fromContext(ctx) | ||
| return c.Select(items, label) | ||
| } | ||
| func (c *cmdIO) Secret(label string) (value string, err error) { | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.