diff --git a/filter/command.go b/filter/command.go index 9cb614a..4fa6e0e 100644 --- a/filter/command.go +++ b/filter/command.go @@ -33,17 +33,15 @@ func (o Options) Run() error { v := viewport.New(o.Width, o.Height) - var choices []string - if input, _ := stdin.Read(); input != "" { - input = strings.TrimSuffix(input, "\n") - if input != "" { - choices = strings.Split(input, "\n") + if len(o.Options) == 0 { + if input, _ := stdin.Read(); input != "" { + o.Options = strings.Split(strings.TrimSuffix(input, "\n"), "\n") + } else { + o.Options = files.List() } - } else { - choices = files.List() } - if len(choices) == 0 { + if len(o.Options) == 0 { return errors.New("no options provided, see `gum filter --help`") } @@ -58,19 +56,19 @@ func (o Options) Run() error { } switch { case o.Value != "" && o.Fuzzy: - matches = fuzzy.Find(o.Value, choices) + matches = fuzzy.Find(o.Value, o.Options) case o.Value != "" && !o.Fuzzy: - matches = exactMatches(o.Value, choices) + matches = exactMatches(o.Value, o.Options) default: - matches = matchAll(choices) + matches = matchAll(o.Options) } if o.NoLimit { - o.Limit = len(choices) + o.Limit = len(o.Options) } p := tea.NewProgram(model{ - choices: choices, + choices: o.Options, indicator: o.Indicator, matches: matches, header: o.Header, diff --git a/filter/options.go b/filter/options.go index 366d757..c295702 100644 --- a/filter/options.go +++ b/filter/options.go @@ -8,6 +8,8 @@ import ( // Options is the customization options for the filter command. type Options struct { + Options []string `arg:"" optional:"" help:"Options to filter."` + Indicator string `help:"Character for selection" default:"•" env:"GUM_FILTER_INDICATOR"` IndicatorStyle style.Styles `embed:"" prefix:"indicator." set:"defaultForeground=212" envprefix:"GUM_FILTER_INDICATOR_"` Limit int `help:"Maximum number of options to pick" default:"1" group:"Selection"`