Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterShell ¶
func RegisterShell(name string, constructor func(config *ShellConfig) (Shell, error))
RegisterShell makes a shell implementation available by the provided name. If RegisterShell is called twice with the same name or if constructor is nil, it panics.
Types ¶
type Args ¶
type Args struct {
// contains filtered or unexported fields
}
Args is the words of the command line.
type Command ¶
type Command struct { Name string Description string Sub Completion }
A Command is the simple completion.
type Completion ¶
type Completion interface { // Complete returns the command line completion reply from args. Complete(ctx context.Context, args *Args) Reply }
Completion is the interface has the completion information.
type Reply ¶
Reply is the alias for map[string]string. The key is the candidate completion word, and the value is the description.
type Shell ¶
type Shell interface { // Args returns the command line arguments. Args() *Args // FormatReply converts the completion reply to the string the script output by Script() can parse. FormatReply(reply Reply, w io.Writer) error // OutputScript outputs the shell script to parse the reply and register the completion. OutputScript(w io.Writer) error // Usage returns how to load the completion script. Usage(cmdline string) string }
Shell is the shell completion interface.
func NewShell ¶
func NewShell(config *ShellConfig) (Shell, error)
NewShell creates a new Shell instances by the provided name.
type ShellConfig ¶
type ShellConfig struct { CommandName string // The name of completion function. CompleteCommand []string // The prefix of completion command. Args []string // The command line arguments. Env map[string]string // The map of environment variables. ShellName string //The name of the shell }
ShellConfig is the configuration for shell.
func NewShellConfig ¶
func NewShellConfig(shell string) *ShellConfig
NewShellConfig returns the default config from command-line arguments and environment variables.