Skip to content

Commit 204d219

Browse files
authored
fix(choose): order when using --label-delimiter (#867)
closes #829
1 parent dbac6a8 commit 204d219

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

choose/command.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package choose
33
import (
44
"errors"
55
"fmt"
6-
"maps"
76
"os"
87
"slices"
98
"sort"
@@ -38,6 +37,8 @@ func (o Options) Run() error {
3837

3938
// normalize options into a map
4039
options := map[string]string{}
40+
// keep the labels in the user-provided order
41+
var labels []string
4142
for _, opt := range o.Options {
4243
if o.LabelDelimiter == "" {
4344
options[opt] = opt
@@ -47,10 +48,11 @@ func (o Options) Run() error {
4748
if !ok {
4849
return fmt.Errorf("invalid option format: %q", opt)
4950
}
51+
labels = append(labels, label)
5052
options[label] = value
5153
}
5254
if o.LabelDelimiter != "" {
53-
o.Options = slices.Collect(maps.Keys(options))
55+
o.Options = labels
5456
}
5557

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

0 commit comments

Comments
 (0)