Skip to content

Commit

Permalink
fix(choose): --ordered (#722)
Browse files Browse the repository at this point in the history
closes #687

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 authored Nov 26, 2024
1 parent 620e645 commit fb11344
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions choose/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"slices"
"strings"

"github.com/charmbracelet/huh"
Expand Down Expand Up @@ -45,6 +46,12 @@ func (o Options) Run() error {
theme.Focused.SelectedPrefix = o.SelectedItemStyle.ToLipgloss().SetString(o.SelectedPrefix)
theme.Focused.UnselectedPrefix = o.ItemStyle.ToLipgloss().SetString(o.UnselectedPrefix)

if o.Ordered {
slices.SortFunc(options, func(a, b huh.Option[string]) int {
return strings.Compare(a.Key, b.Key)
})
}

for _, s := range o.Selected {
for i, opt := range options {
if s == opt.Key || s == opt.Value {
Expand Down

0 comments on commit fb11344

Please sign in to comment.