Action indicates how to complete a flag or positional argument. Cache cashes values of a CompletionCallback for given duration and keys. Chdir changes the current working directory to the named directory for the duration of invocation. ChdirF is like Chdir but uses a function. Filter filters given values.
carapace.ActionValues("A", "B", "C").Filter("B") // ["A", "C"] FilterArgs filters Context.Args. FilterArgs filters Context.Parts. Invoke executes the callback of an action if it exists (supports nesting). List wraps the Action in an ActionMultiParts with given divider. MultiParts splits values of an Action by given dividers and completes each segment separately. MultiPartsP is like MultiParts but with placeholders. NoSpace disables space suffix for given characters (or all if none are given). Prefix adds a prefix to values (only the ones inserted, not the display values).
carapace.ActionValues("melon", "drop", "fall").Prefix("water") Retain retains given values.
carapace.ActionValues("A", "B", "C").Retain("A", "C") // ["A", "C"] Shift shifts positional arguments left `n` times. Split splits `Context.Value` lexicographically and replaces `Context.Args` with the tokens. SplitP is like Split but supports pipelines. Style sets the style.
ActionValues("yes").Style(style.Green)
ActionValues("no").Style(style.Red) Style sets the style using a function.
ActionValues("dir/", "test.txt").StyleF(style.ForPathExt)
ActionValues("true", "false").StyleF(style.ForKeyword) Style sets the style using a reference.
ActionValues("value").StyleR(&style.Carapace.Value)
ActionValues("description").StyleR(&style.Carapace.Value) Suffix adds a suffx to values (only the ones inserted, not the display values).
carapace.ActionValues("apple", "melon", "orange").Suffix("juice") Suppress suppresses specific error messages using regular expressions. Tag sets the tag.
ActionValues("192.168.1.1", "127.0.0.1").Tag("interfaces"). Tag sets the tag using a function.
ActionValues("192.168.1.1", "127.0.0.1").TagF(func(value string) string {
return "interfaces"
}) Timeout sets the maximum duration an Action may take to invoke.
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
time.Sleep(2*time.Second)
return carapace.ActionValues("done")
}).Timeout(1*time.Second, carapace.ActionMessage("timeout exceeded")) UniqueList wraps the Action in an ActionMultiParts with given divider. UniqueListF is like UniqueList but uses a function to transform values before filtering. Usage sets the usage. Usage sets the usage using a function.
func ActionCallback(callback CompletionCallback) Action
func ActionCobra(f func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)) Action
func ActionCommands(cmd *cobra.Command) Action
func ActionDirectories() Action
func ActionExecutables() Action
func ActionExecute(cmd *cobra.Command) Action
func ActionFiles(suffix ...string) Action
func ActionImport(output []byte) Action
func ActionMessage(msg string, args ...interface{}) Action
func ActionMultiParts(sep string, callback func(c Context) Action) Action
func ActionMultiPartsN(sep string, n int, callback func(c Context) Action) Action
func ActionPositional(cmd *cobra.Command) Action
func ActionStyleConfig() Action
func ActionStyledValues(values ...string) Action
func ActionStyledValuesDescribed(values ...string) Action
func ActionStyles(styles ...string) Action
func ActionValues(values ...string) Action
func ActionValuesDescribed(values ...string) Action
func Action.Cache(timeout time.Duration, keys ...pkgcache.Key) Action
func Action.Chdir(dir string) Action
func Action.ChdirF(f func(tc pkgtraverse.Context) (string, error)) Action
func Action.Filter(values ...string) Action
func Action.FilterArgs() Action
func Action.FilterParts() Action
func Action.List(divider string) Action
func Action.MultiParts(dividers ...string) Action
func Action.MultiPartsP(delimiter string, pattern string, f func(placeholder string, matches map[string]string) Action) Action
func Action.NoSpace(suffixes ...rune) Action
func Action.Prefix(prefix string) Action
func Action.Retain(values ...string) Action
func Action.Shift(n int) Action
func Action.Split() Action
func Action.SplitP() Action
func Action.Style(s string) Action
func Action.StyleF(f func(s string, sc style.Context) string) Action
func Action.StyleR(s *string) Action
func Action.Suffix(suffix string) Action
func Action.Suppress(expr ...string) Action
func Action.Tag(tag string) Action
func Action.TagF(f func(s string) string) Action
func Action.Timeout(d time.Duration, alternative Action) Action
func Action.UniqueList(divider string) Action
func Action.UniqueListF(divider string, f func(s string) string) Action
func Action.Usage(usage string, args ...interface{}) Action
func Action.UsageF(f func() string) Action
func InvokedAction.ToA() Action
func InvokedAction.ToMultiPartsA(dividers ...string) Action
func Batch(actions ...Action) batch
func Action.Timeout(d time.Duration, alternative Action) Action
func Carapace.DashAnyCompletion(action Action)
func Carapace.DashCompletion(action ...Action)
func Carapace.PositionalAnyCompletion(action Action)
func Carapace.PositionalCompletion(action ...Action)
ActionMap maps Actions to an identifier.
func Carapace.FlagCompletion(actions ActionMap)
Carapace wraps cobra.Command to define completions. DashAnyCompletion defines completion for any positional arguments after dash (`--`) not already defined. DashCompletion defines completion for positional arguments after dash (`--`) using a list of Actions. FlagCompletion defines completion for flags using a map consisting of name and Action. PositionalAnyCompletion defines completion for any positional arguments not already defined. PositionalCompletion defines completion for positional arguments using a list of Actions. PreInvoke sets a function to alter actions before they are invoked. PreRun sets a function to be run before completion. Snippet creates completion script for given shell. Standalone prevents cobra defaults interfering with standalone mode (e.g. implicit help command).
func Gen(cmd *cobra.Command) *Carapace
CompletionCallback is executed during completion of associated flag or positional argument.
func ActionCallback(callback CompletionCallback) Action
Context provides information during completion. Args contains the positional arguments of current (sub)command (exclusive the one currently being completed). Dir contains the working directory for current context. Env contains environment variables for current context. Parts contains the splitted Value during an ActionMultiParts (exclusive the part currently being completed). Value contains the value currently being completed (or part of it during an ActionMultiParts). Abs returns an absolute representation of path. Command returns the Cmd struct to execute the named program with the given arguments.
Env and Dir are set using the Context.
See exec.Command for most details. Envsubst replaces ${var} in the string based on environment variables in current context. Getenv retrieves the value of the environment variable named by the key. LookupEnv retrieves the value of the environment variable named by the key. Setenv sets the value of the environment variable named by the key.
Context : github.com/rsteube/carapace/pkg/style.Context
Context : github.com/rsteube/carapace/pkg/traverse.Context
func NewContext(args ...string) Context
func Action.Invoke(c Context) InvokedAction
InvokedAction is a logical alias for an Action whose (nested) callback was invoked.ActionAction Cache cashes values of a CompletionCallback for given duration and keys. Chdir changes the current working directory to the named directory for the duration of invocation. ChdirF is like Chdir but uses a function. Filter filters given values.
a := carapace.ActionValues("A", "B", "C").Invoke(c)
b := a.Filter([]string{"B"}) // ["A", "C"] FilterArgs filters Context.Args. FilterArgs filters Context.Parts. Invoke executes the callback of an action if it exists (supports nesting). List wraps the Action in an ActionMultiParts with given divider. Merge merges InvokedActions (existing values are overwritten)
a := carapace.ActionValues("A", "B").Invoke(c)
b := carapace.ActionValues("B", "C").Invoke(c)
c := a.Merge(b) // ["A", "B", "C"] MultiParts splits values of an Action by given dividers and completes each segment separately. MultiPartsP is like MultiParts but with placeholders. NoSpace disables space suffix for given characters (or all if none are given). Prefix adds a prefix to values (only the ones inserted, not the display values)
carapace.ActionValues("melon", "drop", "fall").Invoke(c).Prefix("water") Retain retains given values.
a := carapace.ActionValues("A", "B", "C").Invoke(c)
b := a.Retain([]string{"A", "C"}) // ["A", "C"] Shift shifts positional arguments left `n` times. Split splits `Context.Value` lexicographically and replaces `Context.Args` with the tokens. SplitP is like Split but supports pipelines. Style sets the style.
ActionValues("yes").Style(style.Green)
ActionValues("no").Style(style.Red) Style sets the style using a function.
ActionValues("dir/", "test.txt").StyleF(style.ForPathExt)
ActionValues("true", "false").StyleF(style.ForKeyword) Style sets the style using a reference.
ActionValues("value").StyleR(&style.Carapace.Value)
ActionValues("description").StyleR(&style.Carapace.Value) Suffix adds a suffx to values (only the ones inserted, not the display values)
carapace.ActionValues("apple", "melon", "orange").Invoke(c).Suffix("juice") Suppress suppresses specific error messages using regular expressions. Tag sets the tag.
ActionValues("192.168.1.1", "127.0.0.1").Tag("interfaces"). Tag sets the tag using a function.
ActionValues("192.168.1.1", "127.0.0.1").TagF(func(value string) string {
return "interfaces"
}) Timeout sets the maximum duration an Action may take to invoke.
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
time.Sleep(2*time.Second)
return carapace.ActionValues("done")
}).Timeout(1*time.Second, carapace.ActionMessage("timeout exceeded")) ToA casts an InvokedAction to Action. ToMultiPartsA create an ActionMultiParts from values with given dividers
a := carapace.ActionValues("A/B/C", "A/C", "B/C", "C").Invoke(c)
b := a.ToMultiPartsA("/") // completes segments separately (first one is ["A/", "B/", "C"]) UniqueList wraps the Action in an ActionMultiParts with given divider. UniqueListF is like UniqueList but uses a function to transform values before filtering. Usage sets the usage. Usage sets the usage using a function.
func Action.Invoke(c Context) InvokedAction
func InvokedAction.Filter(values ...string) InvokedAction
func InvokedAction.Merge(others ...InvokedAction) InvokedAction
func InvokedAction.Prefix(prefix string) InvokedAction
func InvokedAction.Retain(values ...string) InvokedAction
func InvokedAction.Suffix(suffix string) InvokedAction
func InvokedAction.Merge(others ...InvokedAction) InvokedAction
Package-Level Functions (total 25)
ActionCallback invokes a go function during completion.
ActionCora bridges given cobra completion function.
ActionCommands completes (sub)commands of given command.
`Context.Args` is used to traverse the command tree further down. Use `Action.Shift` to avoid this.
carapace.Gen(helpCmd).PositionalAnyCompletion(
carapace.ActionCommands(rootCmd),
)
ActionMessage displays a help messages in places where no completions can be generated.
ActionMultiParts completes parts of an argument separated by sep.
ActionMultiPartsN is like ActionMultiParts but limits the number of parts to `n`.
ActionPositional completes positional arguments for given command ignoring `--` (dash).
TODO: experimental - likely gives issues with preinvoke (does not have the full args)
carapace.Gen(cmd).DashAnyCompletion(
carapace.ActionPositional(cmd),
)
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.