diff --git a/cmd/list.go b/cmd/list.go index 9c9ea07..d1d3b02 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -42,22 +42,6 @@ var listCmd = &cobra.Command{ RunE: list, } -type ListArgs struct { - header bool - key bool - value bool - ttl bool - binary bool - secrets bool - render func(table.Writer) -} - -type listFormat struct { - limitColumns bool - style *table.Style - render func(table.Writer) -} - func list(cmd *cobra.Command, args []string) error { store := &Store{} targetDB := "@default" @@ -162,37 +146,6 @@ func list(cmd *cobra.Command, args []string) error { return nil } -// formatEnum implements pflag.Value -type formatEnum string - -func (e *formatEnum) String() string { - return string(*e) -} - -func (e *formatEnum) Set(v string) error { - switch v { - case "table", "csv", "html", "markdown": - *e = formatEnum(v) - return nil - default: - return errors.New(`must be one of "table", "csv", "html", or "markdown"`) - } -} - -func (e *formatEnum) Type() string { - return "format" -} - -var ( - binary bool = false - secret bool = false - noKeys bool = false - noValues bool = false - ttl bool = false - noHeader bool = false - format formatEnum = "table" -) - func init() { listCmd.Flags().BoolVarP(&binary, "binary", "b", false, "include binary data in text output") listCmd.Flags().BoolVarP(&secret, "secret", "S", false, "display values marked as secret") @@ -204,34 +157,6 @@ func init() { rootCmd.AddCommand(listCmd) } -func parseFlags(cmd *cobra.Command) (ListArgs, error) { - var renderFunc func(tw table.Writer) - switch format.String() { - case "csv": - renderFunc = func(tw table.Writer) { tw.RenderCSV() } - case "html": - renderFunc = func(tw table.Writer) { tw.RenderHTML() } - case "markdown": - renderFunc = func(tw table.Writer) { tw.RenderMarkdown() } - default: - renderFunc = func(tw table.Writer) { tw.Render() } - - } - if noKeys && noValues && !ttl { - return ListArgs{}, fmt.Errorf("no columns selected; disable --no-keys/--no-values or pass --ttl") - } - - return ListArgs{ - header: !noHeader, - key: !noKeys, - value: !noValues, - ttl: ttl, - binary: binary, - render: renderFunc, - secrets: secret, - }, nil -} - type columnKind int const ( diff --git a/cmd/list_flags.go b/cmd/list_flags.go new file mode 100644 index 0000000..04bc427 --- /dev/null +++ b/cmd/list_flags.go @@ -0,0 +1,78 @@ +package cmd + +import ( + "fmt" + + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" +) + +// ListArgs tracks the resolved flag configuration for the list command. +type ListArgs struct { + header bool + key bool + value bool + ttl bool + binary bool + secrets bool + render func(table.Writer) +} + +// formatEnum implements pflag.Value for format selection. +type formatEnum string + +func (e *formatEnum) String() string { + return string(*e) +} + +func (e *formatEnum) Set(v string) error { + switch v { + case "table", "csv", "html", "markdown": + *e = formatEnum(v) + return nil + default: + return fmt.Errorf("must be one of \"table\", \"csv\", \"html\", or \"markdown\"") + } +} + +func (e *formatEnum) Type() string { + return "format" +} + +var ( + binary bool = false + secret bool = false + noKeys bool = false + noValues bool = false + ttl bool = false + noHeader bool = false + format formatEnum = "table" +) + +func parseFlags(cmd *cobra.Command) (ListArgs, error) { + var renderFunc func(tw table.Writer) + switch format.String() { + case "csv": + renderFunc = func(tw table.Writer) { tw.RenderCSV() } + case "html": + renderFunc = func(tw table.Writer) { tw.RenderHTML() } + case "markdown": + renderFunc = func(tw table.Writer) { tw.RenderMarkdown() } + default: + renderFunc = func(tw table.Writer) { tw.Render() } + } + + if noKeys && noValues && !ttl { + return ListArgs{}, fmt.Errorf("no columns selected; disable --no-keys/--no-values or pass --ttl") + } + + return ListArgs{ + header: !noHeader, + key: !noKeys, + value: !noValues, + ttl: ttl, + binary: binary, + render: renderFunc, + secrets: secret, + }, nil +}