From 54f85439faaedb4323d462956b5b7c982916088e Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Wed, 13 Jul 2022 12:10:38 -0400 Subject: [PATCH] feat(choose): --no-limit flag alias Adds a --no-limit flag as an alias to set the limit to the number of options available. --- choose/command.go | 12 +++++++++++- choose/options.go | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/choose/command.go b/choose/command.go index c22e441..afe8c8e 100644 --- a/choose/command.go +++ b/choose/command.go @@ -1,6 +1,7 @@ package choose import ( + "errors" "fmt" "os" "strings" @@ -14,6 +15,9 @@ import ( func (o Options) Run() error { if len(o.Options) == 0 { input, _ := stdin.Read() + if input == "" { + return errors.New("no options provided, see `gum choose --help`") + } o.Options = strings.Split(strings.TrimSpace(input), "\n") } @@ -24,12 +28,18 @@ func (o Options) Run() error { // We don't need to display prefixes if we are only picking one option. // Simply displaying the cursor is enough. - if o.Limit == 1 { + if o.Limit == 1 && !o.NoLimit { o.SelectedPrefix = "" o.UnselectedPrefix = "" o.CursorPrefix = "" } + // If we've set no limit then we can simply select as many options as there + // are so let's set the limit to the number of options. + if o.NoLimit { + o.Limit = len(o.Options) + } + m, err := tea.NewProgram(model{ height: o.Height, cursor: o.Cursor, diff --git a/choose/options.go b/choose/options.go index d2d2b6f..e2702f8 100644 --- a/choose/options.go +++ b/choose/options.go @@ -6,7 +6,8 @@ import "github.com/charmbracelet/gum/style" type Options struct { Options []string `arg:"" optional:"" help:"Options to choose from."` - Limit int `help:"Maximum number of options to pick" default:"1"` + Limit int `help:"Maximum number of options to pick" default:"1" group:"Selection"` + NoLimit bool `help:"Pick unlimited number of options (ignores limit)" group:"Selection"` Height int `help:"Height of the list" default:"10"` Cursor string `help:"Prefix to show on item that corresponds to the cursor position" default:"> "` CursorPrefix string `help:"Prefix to show on the cursor item (hidden if limit is 1)" default:"• "`