Documentation ¶
Index ¶
- func ActionExecCommand(name string, arg ...string) func(f func(output []byte) Action) Action
- func IsCallback() bool
- func Test(t testingT)
- type Action
- func ActionCallback(callback CompletionCallback) Action
- func ActionDirectories() Action
- func ActionFiles(suffix ...string) Action
- func ActionMessage(msg string) Action
- func ActionMultiParts(divider string, callback func(c Context) Action) Action
- func ActionValues(values ...string) Action
- func ActionValuesDescribed(values ...string) Action
- type ActionMap
- type Carapace
- type CompletionCallback
- type Context
- type InvokedAction
- func (a InvokedAction) Filter(values []string) InvokedAction
- func (a InvokedAction) Merge(others ...InvokedAction) InvokedAction
- func (a InvokedAction) Prefix(prefix string) InvokedAction
- func (a InvokedAction) Suffix(suffix string) InvokedAction
- func (a InvokedAction) ToA() Action
- func (a InvokedAction) ToMultiPartsA(divider string) Action
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ActionExecCommand ¶ added in v0.5.8
ActionExecCommand invokes given command and transforms its output using given function on success or returns ActionMessage with the first line of stderr if available.
carapace.ActionExecCommand("git", "remote")(func(output []byte) carapace.Action { lines := strings.Split(string(output), "\n") return carapace.ActionValues(lines[:len(lines)-1]...) })
func IsCallback ¶ added in v0.0.6
func IsCallback() bool
IsCallback returns true if current program invocation is a callback
Types ¶
type Action ¶
type Action struct {
// contains filtered or unexported fields
}
Action indicates how to complete a flag or positional argument
func ActionCallback ¶
func ActionCallback(callback CompletionCallback) Action
ActionCallback invokes a go function during completion
func ActionDirectories ¶ added in v0.0.11
func ActionDirectories() Action
ActionDirectories completes directories
func ActionFiles ¶
ActionFiles completes files with optional suffix filtering
func ActionMessage ¶
ActionMessage displays a help messages in places where no completions can be generated
func ActionMultiParts ¶
ActionMultiParts completes multiple parts of words separately where each part is separated by some char (CallbackValue is set to the currently completed part during invocation)
func ActionValues ¶
ActionValues completes arbitrary keywords (values)
func ActionValuesDescribed ¶
ActionValuesDescribed completes arbitrary key (values) with an additional description (value, description pairs)
func (Action) Cache ¶ added in v0.2.4
Cache cashes values of a CompletionCallback for given duration and keys
func (Action) Invoke ¶ added in v0.1.1
func (a Action) Invoke(c Context) InvokedAction
Invoke executes the callback of an action if it exists (supports nesting)
type Carapace ¶
type Carapace struct {
// contains filtered or unexported fields
}
Carapace wraps cobra.Command to define completions
func (Carapace) FlagCompletion ¶
FlagCompletion defines completion for flags using a map consisting of name and Action
func (Carapace) PositionalAnyCompletion ¶ added in v0.0.14
PositionalAnyCompletion defines completion for any positional argument not already defined
func (Carapace) PositionalCompletion ¶
PositionalCompletion defines completion for positional arguments using a list of Actions
func (Carapace) Standalone ¶ added in v0.0.14
func (c Carapace) Standalone()
Standalone prevents cobra defaults interfering with standalone mode (e.g. implicit help command)
type CompletionCallback ¶
CompletionCallback is executed during completion of associated flag or positional argument
type Context ¶ added in v0.4.0
type Context struct { // CallbackValue contains the (partial) value (or part of it during an ActionMultiParts) currently being completed CallbackValue string // Args contains the positional arguments of current (sub)command (exclusive the one currently being completed) Args []string // Parts contains the splitted CallbackValue during an ActionMultiParts (exclusive the part currently being completed) Parts []string }
Context provides information during completion
type InvokedAction ¶ added in v0.1.1
type InvokedAction Action
InvokedAction is a logical alias for an Action whose (nested) callback was invoked
func (InvokedAction) Filter ¶ added in v0.1.1
func (a InvokedAction) Filter(values []string) InvokedAction
Filter filters given values (this should be done before any call to Prefix/Suffix as those alter the values being filtered)
a := carapace.ActionValues("A", "B", "C").Invoke(c) b := a.Filter([]string{"B"}) // ["A", "C"]
func (InvokedAction) Merge ¶ added in v0.1.8
func (a InvokedAction) Merge(others ...InvokedAction) InvokedAction
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"]
func (InvokedAction) Prefix ¶ added in v0.1.1
func (a InvokedAction) Prefix(prefix string) InvokedAction
Prefix adds a prefix to values (only the ones inserted, not the display values)
a := carapace.ActionValues("melon", "drop", "fall").Invoke(c) b := a.Prefix("water") // ["watermelon", "waterdrop", "waterfall"] but display still ["melon", "drop", "fall"]
func (InvokedAction) Suffix ¶ added in v0.1.1
func (a InvokedAction) Suffix(suffix string) InvokedAction
Suffix adds a suffx to values (only the ones inserted, not the display values)
a := carapace.ActionValues("apple", "melon", "orange").Invoke(c) b := a.Suffix("juice") // ["applejuice", "melonjuice", "orangejuice"] but display still ["apple", "melon", "orange"]
func (InvokedAction) ToA ¶ added in v0.1.1
func (a InvokedAction) ToA() Action
ToA casts an InvokedAction to Action
func (InvokedAction) ToMultiPartsA ¶ added in v0.2.2
func (a InvokedAction) ToMultiPartsA(divider string) Action
ToMultiPartsA create an ActionMultiParts from values with given divider
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"])