Skip to content

Commit

Permalink
fix(choose): order when using --label-delimiter (#867)
Browse files Browse the repository at this point in the history
closes #829
  • Loading branch information
caarlos0 authored Mar 6, 2025
1 parent dbac6a8 commit 204d219
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions choose/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package choose
import (
"errors"
"fmt"
"maps"
"os"
"slices"
"sort"
Expand Down Expand Up @@ -38,6 +37,8 @@ func (o Options) Run() error {

// normalize options into a map
options := map[string]string{}
// keep the labels in the user-provided order
var labels []string

Check failure on line 41 in choose/command.go

View workflow job for this annotation

GitHub Actions / lint-soft

Consider pre-allocating `labels` (prealloc)
for _, opt := range o.Options {
if o.LabelDelimiter == "" {
options[opt] = opt
Expand All @@ -47,10 +48,11 @@ func (o Options) Run() error {
if !ok {
return fmt.Errorf("invalid option format: %q", opt)
}
labels = append(labels, label)
options[label] = value
}
if o.LabelDelimiter != "" {
o.Options = slices.Collect(maps.Keys(options))
o.Options = labels
}

if o.SelectIfOne && len(o.Options) == 1 {
Expand Down

0 comments on commit 204d219

Please sign in to comment.