gum: common flag completion

This commit is contained in:
rsteube 2025-01-14 09:26:12 +01:00
parent 91b650655e
commit fa17247fc4
12 changed files with 56 additions and 350 deletions

View File

@ -2,7 +2,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/spf13/cobra"
)
@ -94,33 +94,10 @@ func init() {
chooseCmd.Flags().String("unselected-prefix", "", "Prefix to show on unselected items (hidden if limit is 1)")
rootCmd.AddCommand(chooseCmd)
common.AddFlagCompletion(chooseCmd)
carapace.Gen(chooseCmd).FlagCompletion(carapace.ActionMap{
"cursor.align": gum.ActionAlignments(),
"cursor.background": gum.ActionColors(),
"cursor.border": gum.ActionBorders(),
"cursor.border-background": gum.ActionColors(),
"cursor.border-foreground": gum.ActionColors(),
"cursor.foreground": gum.ActionColors(),
"header.align": gum.ActionAlignments(),
"header.background": gum.ActionColors(),
"header.border": gum.ActionBorders(),
"header.border-background": gum.ActionColors(),
"header.border-foreground": gum.ActionColors(),
"header.foreground": gum.ActionColors(),
"item.align": gum.ActionAlignments(),
"item.background": gum.ActionColors(),
"item.border": gum.ActionBorders(),
"item.border-background": gum.ActionColors(),
"item.border-foreground": gum.ActionColors(),
"item.foreground": gum.ActionColors(),
"selected": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionValues(c.Args...).UniqueList(",")
}),
"selected.align": gum.ActionAlignments(),
"selected.background": gum.ActionColors(),
"selected.border": gum.ActionBorders(),
"selected.border-background": gum.ActionColors(),
"selected.border-foreground": gum.ActionColors(),
"selected.foreground": gum.ActionColors(),
})
}

View File

@ -0,0 +1,27 @@
package common
import (
"path/filepath"
"strings"
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
func AddFlagCompletion(cmd *cobra.Command) {
m := make(carapace.ActionMap)
cmd.Flags().VisitAll(func(f *pflag.Flag) {
switch strings.TrimPrefix(filepath.Ext(f.Name), ".") {
case "background", "foreground", "border-background", "border-foreground":
m[f.Name] = gum.ActionColors()
case "align":
m[f.Name] = gum.ActionAlignments()
case "border":
m[f.Name] = gum.ActionBorders()
}
})
carapace.Gen(cmd).FlagCompletion(m)
}

View File

@ -2,7 +2,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/spf13/cobra"
)
@ -68,24 +68,5 @@ func init() {
confirmCmd.Flags().String("unselected.width", "", "Text width")
rootCmd.AddCommand(confirmCmd)
carapace.Gen(confirmCmd).FlagCompletion(carapace.ActionMap{
"prompt.align": gum.ActionAlignments(),
"prompt.background": gum.ActionColors(),
"prompt.border": gum.ActionBorders(),
"prompt.border-background": gum.ActionColors(),
"prompt.border-foreground": gum.ActionColors(),
"prompt.foreground": gum.ActionColors(),
"selected.align": gum.ActionAlignments(),
"selected.background": gum.ActionColors(),
"selected.border": gum.ActionBorders(),
"selected.border-background": gum.ActionColors(),
"selected.border-foreground": gum.ActionColors(),
"selected.foreground": gum.ActionColors(),
"unselected.align": gum.ActionAlignments(),
"unselected.background": gum.ActionColors(),
"unselected.border": gum.ActionBorders(),
"unselected.border-background": gum.ActionColors(),
"unselected.border-foreground": gum.ActionColors(),
"unselected.foreground": gum.ActionColors(),
})
common.AddFlagCompletion(confirmCmd)
}

View File

@ -2,7 +2,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/spf13/cobra"
)
@ -147,50 +147,7 @@ func init() {
fileCmd.Flags().String("timeout", "", "Timeout until command aborts without a selection")
rootCmd.AddCommand(fileCmd)
carapace.Gen(fileCmd).FlagCompletion(carapace.ActionMap{
"cursor.align": gum.ActionAlignments(),
"cursor.background": gum.ActionColors(),
"cursor.border": gum.ActionBorders(),
"cursor.border-background": gum.ActionColors(),
"cursor.border-foreground": gum.ActionColors(),
"cursor.foreground": gum.ActionColors(),
"directory.align": gum.ActionAlignments(),
"directory.background": gum.ActionColors(),
"directory.border": gum.ActionBorders(),
"directory.border-background": gum.ActionColors(),
"directory.border-foreground": gum.ActionColors(),
"directory.foreground": gum.ActionColors(),
"file-size.align": gum.ActionAlignments(),
"file-size.background": gum.ActionColors(),
"file-size.border": gum.ActionBorders(),
"file-size.border-background": gum.ActionColors(),
"file-size.border-foreground": gum.ActionColors(),
"file-size.foreground": gum.ActionColors(),
"file.align": gum.ActionAlignments(),
"file.background": gum.ActionColors(),
"file.border": gum.ActionBorders(),
"file.border-background": gum.ActionColors(),
"file.border-foreground": gum.ActionColors(),
"file.foreground": gum.ActionColors(),
"permissions.align": gum.ActionAlignments(),
"permissions.background": gum.ActionColors(),
"permissions.border": gum.ActionBorders(),
"permissions.border-background": gum.ActionColors(),
"permissions.border-foreground": gum.ActionColors(),
"permissions.foreground": gum.ActionColors(),
"selected.align": gum.ActionAlignments(),
"selected.background": gum.ActionColors(),
"selected.border": gum.ActionBorders(),
"selected.border-background": gum.ActionColors(),
"selected.border-foreground": gum.ActionColors(),
"selected.foreground": gum.ActionColors(),
"symlink.align": gum.ActionAlignments(),
"symlink.background": gum.ActionColors(),
"symlink.border": gum.ActionBorders(),
"symlink.border-background": gum.ActionColors(),
"symlink.border-foreground": gum.ActionColors(),
"symlink.foreground": gum.ActionColors(),
})
common.AddFlagCompletion(fileCmd)
carapace.Gen(fileCmd).PositionalCompletion(
carapace.ActionDirectories(),

View File

@ -2,7 +2,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/spf13/cobra"
)
@ -175,60 +175,5 @@ func init() {
filterCmd.Flags().String("width", "", "Input width")
rootCmd.AddCommand(filterCmd)
carapace.Gen(filterCmd).FlagCompletion(carapace.ActionMap{
"cursor-text.align": gum.ActionAlignments(),
"cursor-text.background": gum.ActionColors(),
"cursor-text.border": gum.ActionBorders(),
"cursor-text.border-background": gum.ActionColors(),
"cursor-text.border-foreground": gum.ActionColors(),
"cursor-text.foreground": gum.ActionColors(),
"header.align": gum.ActionAlignments(),
"header.background": gum.ActionColors(),
"header.border": gum.ActionBorders(),
"header.border-background": gum.ActionColors(),
"header.border-foreground": gum.ActionColors(),
"header.foreground": gum.ActionColors(),
"indicator.align": gum.ActionAlignments(),
"indicator.background": gum.ActionColors(),
"indicator.border": gum.ActionBorders(),
"indicator.border-background": gum.ActionColors(),
"indicator.border-foreground": gum.ActionColors(),
"indicator.foreground": gum.ActionColors(),
"match.align": gum.ActionAlignments(),
"match.background": gum.ActionColors(),
"match.border": gum.ActionBorders(),
"match.border-background": gum.ActionColors(),
"match.border-foreground": gum.ActionColors(),
"match.foreground": gum.ActionColors(),
"placeholder.align": gum.ActionAlignments(),
"placeholder.background": gum.ActionColors(),
"placeholder.border": gum.ActionBorders(),
"placeholder.border-background": gum.ActionColors(),
"placeholder.border-foreground": gum.ActionColors(),
"placeholder.foreground": gum.ActionColors(),
"prompt.align": gum.ActionAlignments(),
"prompt.background": gum.ActionColors(),
"prompt.border": gum.ActionBorders(),
"prompt.border-background": gum.ActionColors(),
"prompt.border-foreground": gum.ActionColors(),
"prompt.foreground": gum.ActionColors(),
"selected-indicator.align": gum.ActionAlignments(),
"selected-indicator.background": gum.ActionColors(),
"selected-indicator.border": gum.ActionBorders(),
"selected-indicator.border-background": gum.ActionColors(),
"selected-indicator.border-foreground": gum.ActionColors(),
"selected-indicator.foreground": gum.ActionColors(),
"text.align": gum.ActionAlignments(),
"text.background": gum.ActionColors(),
"text.border": gum.ActionBorders(),
"text.border-background": gum.ActionColors(),
"text.border-foreground": gum.ActionColors(),
"text.foreground": gum.ActionColors(),
"unselected-prefix.align": gum.ActionAlignments(),
"unselected-prefix.background": gum.ActionColors(),
"unselected-prefix.border": gum.ActionBorders(),
"unselected-prefix.border-background": gum.ActionColors(),
"unselected-prefix.border-foreground": gum.ActionColors(),
"unselected-prefix.foreground": gum.ActionColors(),
})
common.AddFlagCompletion(filterCmd)
}

View File

@ -2,6 +2,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/spf13/cobra"
)
@ -88,31 +89,8 @@ func init() {
inputCmd.Flags().String("width", "", "Input width (0 for terminal width)")
rootCmd.AddCommand(inputCmd)
common.AddFlagCompletion(inputCmd)
carapace.Gen(inputCmd).FlagCompletion(carapace.ActionMap{
"cursor.align": gum.ActionAlignments(),
"cursor.background": gum.ActionColors(),
"cursor.border": gum.ActionBorders(),
"cursor.border-background": gum.ActionColors(),
"cursor.border-foreground": gum.ActionColors(),
"cursor.foreground": gum.ActionColors(),
"cursor.mode": gum.ActionCursorModes(),
"header.align": gum.ActionAlignments(),
"header.background": gum.ActionColors(),
"header.border": gum.ActionBorders(),
"header.border-background": gum.ActionColors(),
"header.border-foreground": gum.ActionColors(),
"header.foreground": gum.ActionColors(),
"placeholder.align": gum.ActionAlignments(),
"placeholder.background": gum.ActionColors(),
"placeholder.border": gum.ActionBorders(),
"placeholder.border-background": gum.ActionColors(),
"placeholder.border-foreground": gum.ActionColors(),
"placeholder.foreground": gum.ActionColors(),
"prompt.align": gum.ActionAlignments(),
"prompt.background": gum.ActionColors(),
"prompt.border": gum.ActionBorders(),
"prompt.border-background": gum.ActionColors(),
"prompt.border-foreground": gum.ActionColors(),
"prompt.foreground": gum.ActionColors(),
"cursor.mode": gum.ActionCursorModes(),
})
}

View File

@ -2,7 +2,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/spf13/cobra"
)
@ -20,7 +20,5 @@ func init() {
joinCmd.Flags().Bool("vertical", false, "Join (potentially multi-line) strings vertically")
rootCmd.AddCommand(joinCmd)
carapace.Gen(joinCmd).FlagCompletion(carapace.ActionMap{
"align": gum.ActionAlignments(),
})
common.AddFlagCompletion(joinCmd)
}

View File

@ -4,7 +4,7 @@ import (
"time"
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/carapace-sh/carapace/pkg/style"
"github.com/spf13/cobra"
)
@ -133,40 +133,11 @@ func init() {
logCmd.Flags().String("value.width", "", "Text width")
rootCmd.AddCommand(logCmd)
common.AddFlagCompletion(logCmd)
carapace.Gen(logCmd).FlagCompletion(carapace.ActionMap{
"file": carapace.ActionFiles(),
"formatter": carapace.ActionValues("json", "logfmt", "text"),
"key.align": gum.ActionAlignments(),
"key.background": gum.ActionColors(),
"key.border": gum.ActionBorders(),
"key.border-background": gum.ActionColors(),
"key.border-foreground": gum.ActionColors(),
"key.foreground": gum.ActionColors(),
"level": carapace.ActionValues("none", "debug", "info", "warn", "error", "fatal").StyleF(style.ForLogLevel),
"level.align": gum.ActionAlignments(),
"level.background": gum.ActionColors(),
"level.border": gum.ActionBorders(),
"level.border-background": gum.ActionColors(),
"level.border-foreground": gum.ActionColors(),
"level.foreground": gum.ActionColors(),
"message.align": gum.ActionAlignments(),
"message.background": gum.ActionColors(),
"message.border": gum.ActionBorders(),
"message.border-background": gum.ActionColors(),
"message.border-foreground": gum.ActionColors(),
"message.foreground": gum.ActionColors(),
"prefix.align": gum.ActionAlignments(),
"prefix.background": gum.ActionColors(),
"prefix.border": gum.ActionBorders(),
"prefix.border-background": gum.ActionColors(),
"prefix.border-foreground": gum.ActionColors(),
"prefix.foreground": gum.ActionColors(),
"separator.align": gum.ActionAlignments(),
"separator.background": gum.ActionColors(),
"separator.border": gum.ActionBorders(),
"separator.border-background": gum.ActionColors(),
"separator.border-foreground": gum.ActionColors(),
"separator.foreground": gum.ActionColors(),
"file": carapace.ActionFiles(),
"formatter": carapace.ActionValues("json", "logfmt", "text"),
"level": carapace.ActionValues("none", "debug", "info", "warn", "error", "fatal").StyleF(style.ForLogLevel),
"time": carapace.ActionValuesDescribed(
"layout", time.Layout,
"ansic", time.ANSIC,
@ -187,17 +158,5 @@ func init() {
"datetime", "2006-01-02 15:04:05",
"dateonly", "2006-01-02",
"timeonly", "15:04:05"),
"time.align": gum.ActionAlignments(),
"time.background": gum.ActionColors(),
"time.border": gum.ActionBorders(),
"time.border-background": gum.ActionColors(),
"time.border-foreground": gum.ActionColors(),
"time.foreground": gum.ActionColors(),
"value.align": gum.ActionAlignments(),
"value.background": gum.ActionColors(),
"value.border": gum.ActionBorders(),
"value.border-background": gum.ActionColors(),
"value.border-foreground": gum.ActionColors(),
"value.foreground": gum.ActionColors(),
})
}

View File

@ -2,7 +2,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/spf13/cobra"
)
@ -95,36 +95,5 @@ func init() {
pagerCmd.Flags().String("width", "", "Text width")
rootCmd.AddCommand(pagerCmd)
carapace.Gen(pagerCmd).FlagCompletion(carapace.ActionMap{
"align": gum.ActionAlignments(),
"background": gum.ActionColors(),
"border": gum.ActionBorders(),
"border-background": gum.ActionColors(),
"border-foreground": gum.ActionColors(),
"foreground": gum.ActionColors(),
"help.align": gum.ActionAlignments(),
"help.background": gum.ActionColors(),
"help.border": gum.ActionBorders(),
"help.border-background": gum.ActionColors(),
"help.border-foreground": gum.ActionColors(),
"help.foreground": gum.ActionColors(),
"line-number.align": gum.ActionAlignments(),
"line-number.background": gum.ActionColors(),
"line-number.border": gum.ActionBorders(),
"line-number.border-background": gum.ActionColors(),
"line-number.border-foreground": gum.ActionColors(),
"line-number.foreground": gum.ActionColors(),
"match-highlight.align": gum.ActionAlignments(),
"match-highlight.background": gum.ActionColors(),
"match-highlight.border": gum.ActionBorders(),
"match-highlight.border-background": gum.ActionColors(),
"match-highlight.border-foreground": gum.ActionColors(),
"match-highlight.foreground": gum.ActionColors(),
"match.align": gum.ActionAlignments(),
"match.background": gum.ActionColors(),
"match.border": gum.ActionBorders(),
"match.border-background": gum.ActionColors(),
"match.border-foreground": gum.ActionColors(),
"match.foreground": gum.ActionColors(),
})
common.AddFlagCompletion(pagerCmd)
}

View File

@ -2,7 +2,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/carapace-sh/carapace-bridge/pkg/actions/bridge"
"github.com/spf13/cobra"
)
@ -57,8 +57,9 @@ func init() {
spinCmd.Flags().String("title.width", "", "Text width")
rootCmd.AddCommand(spinCmd)
common.AddFlagCompletion(spinCmd)
carapace.Gen(spinCmd).FlagCompletion(carapace.ActionMap{
"align": carapace.ActionValues("left", "right"),
"align": carapace.ActionValues("left", "right"), // differs from gum.ActionAlignments
"spinner": carapace.ActionValuesDescribed(
"line", "/",
"dot", "⢿",
@ -72,17 +73,6 @@ func init() {
"meter", "▰",
"hamburger", "☲",
),
"spinner.background": gum.ActionColors(),
"spinner.border": gum.ActionBorders(),
"spinner.border-background": gum.ActionColors(),
"spinner.border-foreground": gum.ActionColors(),
"spinner.foreground": gum.ActionColors(),
"title.align": gum.ActionAlignments(),
"title.background": gum.ActionColors(),
"title.border": gum.ActionBorders(),
"title.border-background": gum.ActionColors(),
"title.border-foreground": gum.ActionColors(),
"title.foreground": gum.ActionColors(),
})
carapace.Gen(spinCmd).PositionalAnyCompletion(

View File

@ -2,7 +2,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/spf13/cobra"
)
@ -89,31 +89,8 @@ func init() {
tableCmd.Flags().StringSliceP("widths", "w", []string{}, "Column widths")
rootCmd.AddCommand(tableCmd)
common.AddFlagCompletion(tableCmd)
carapace.Gen(tableCmd).FlagCompletion(carapace.ActionMap{
"border": gum.ActionBorders(),
"border.align": gum.ActionAlignments(),
"border.background": gum.ActionColors(),
"border.border": gum.ActionBorders(),
"border.border-background": gum.ActionColors(),
"border.border-foreground": gum.ActionColors(),
"border.foreground": gum.ActionColors(),
"cell.background": gum.ActionColors(),
"cell.border": gum.ActionBorders(),
"cell.border-background": gum.ActionColors(),
"cell.border-foreground": gum.ActionColors(),
"cell.foreground": gum.ActionColors(),
"file": carapace.ActionFiles(),
"header.align": gum.ActionAlignments(),
"header.background": gum.ActionColors(),
"header.border": gum.ActionBorders(),
"header.border-background": gum.ActionColors(),
"header.border-foreground": gum.ActionColors(),
"header.foreground": gum.ActionColors(),
"selected.align": gum.ActionAlignments(),
"selected.background": gum.ActionColors(),
"selected.border": gum.ActionBorders(),
"selected.border-background": gum.ActionColors(),
"selected.border-foreground": gum.ActionColors(),
"selected.foreground": gum.ActionColors(),
"file": carapace.ActionFiles(),
})
}

View File

@ -2,6 +2,7 @@ package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/completers/gum_completer/cmd/common"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/gum"
"github.com/spf13/cobra"
)
@ -166,61 +167,8 @@ func init() {
writeCmd.Flags().String("width", "", "Text area width (0 for terminal width)")
rootCmd.AddCommand(writeCmd)
common.AddFlagCompletion(writeCmd)
carapace.Gen(writeCmd).FlagCompletion(carapace.ActionMap{
"base.align": gum.ActionAlignments(),
"base.background": gum.ActionColors(),
"base.border": gum.ActionBorders(),
"base.border-background": gum.ActionColors(),
"base.border-foreground": gum.ActionColors(),
"base.foreground": gum.ActionColors(),
"cursor-line-number.align": gum.ActionAlignments(),
"cursor-line-number.background": gum.ActionColors(),
"cursor-line-number.border": gum.ActionBorders(),
"cursor-line-number.border-background": gum.ActionColors(),
"cursor-line-number.border-foreground": gum.ActionColors(),
"cursor-line-number.foreground": gum.ActionColors(),
"cursor-line.align": gum.ActionAlignments(),
"cursor-line.background": gum.ActionColors(),
"cursor-line.border": gum.ActionBorders(),
"cursor-line.border-background": gum.ActionColors(),
"cursor-line.border-foreground": gum.ActionColors(),
"cursor-line.foreground": gum.ActionColors(),
"cursor.align": gum.ActionAlignments(),
"cursor.background": gum.ActionColors(),
"cursor.border": gum.ActionBorders(),
"cursor.border-background": gum.ActionColors(),
"cursor.border-foreground": gum.ActionColors(),
"cursor.foreground": gum.ActionColors(),
"cursor.mode": gum.ActionCursorModes(),
"end-of-buffer.align": gum.ActionAlignments(),
"end-of-buffer.background": gum.ActionColors(),
"end-of-buffer.border": gum.ActionBorders(),
"end-of-buffer.border-background": gum.ActionColors(),
"end-of-buffer.border-foreground": gum.ActionColors(),
"end-of-buffer.foreground": gum.ActionColors(),
"header.align": gum.ActionAlignments(),
"header.background": gum.ActionColors(),
"header.border": gum.ActionBorders(),
"header.border-background": gum.ActionColors(),
"header.border-foreground": gum.ActionColors(),
"header.foreground": gum.ActionColors(),
"line-number.align": gum.ActionAlignments(),
"line-number.background": gum.ActionColors(),
"line-number.border": gum.ActionBorders(),
"line-number.border-background": gum.ActionColors(),
"line-number.border-foreground": gum.ActionColors(),
"line-number.foreground": gum.ActionColors(),
"placeholder.align": gum.ActionAlignments(),
"placeholder.background": gum.ActionColors(),
"placeholder.border": gum.ActionBorders(),
"placeholder.border-background": gum.ActionColors(),
"placeholder.border-foreground": gum.ActionColors(),
"placeholder.foreground": gum.ActionColors(),
"prompt.align": gum.ActionAlignments(),
"prompt.background": gum.ActionColors(),
"prompt.border": gum.ActionBorders(),
"prompt.border-background": gum.ActionColors(),
"prompt.border-foreground": gum.ActionColors(),
"prompt.foreground": gum.ActionColors(),
"cursor.mode": gum.ActionCursorModes(),
})
}