Context
Context
provides information during completion.
type Context struct {
Value string
Args []string
Parts []string
Env []string
Dir string
}
Key | Description |
---|---|
Value | current value being completed |
Args | positional arguments of current (sub)command |
Parts | splitted Value during an ActionMultiParts |
Dir | working directory |
Examples
Default with flag parsing enabled.
command pos1 --flag1 pos2 --f<TAB>
# Value: --f
# Args: [pos1, pos2]
After encountering --
(dash) further flag parsing is disabled and Context.Args
is reset to only contain dash arguments.
command pos1 --flag1 pos2 -- dash1 <TAB>
# Value:
# Args: [dash1]
With Command.DisableFlagParsing
to true
all arguments are handled as positional.
command pos1 --flag1 pos2 -- dash1 d<TAB>
# Value: d
# Args: [pos1, --flag1, pos2, --, dash1]
With SetInterspersed
to false
flag parsing is disabled after encountering the first positional argument.
command --flag1 flagArg1 pos1 -- dash1 --flag2 d<TAB>
# Value: d
# Args: [pos1, --, dash1, --flag2]
ActionMultiParts is a special case where Context.Parts
is filled with the splitted Context.Value
.
ActionValues("part1", "part2", "part3").UniqueList(",")
command pos1 part1,part2,p<TAB>
# Value: p
# Args: [pos1]
# Parts: [part1, part2]