gomplete

package module
v0.0.0-...-a14623b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2019 License: MIT Imports: 8 Imported by: 0

README

gomplete

GoDoc Go Report Card GolangCI CircleCI codecov

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.

func Shells

func Shells() []string

Shells returns a list of the names of the registered shells.

Types

type Args

type Args struct {
	// contains filtered or unexported fields
}

Args is the words of the command line.

func NewArgs

func NewArgs(words []string) *Args

NewArgs returns an Args from the slice of string.

func (*Args) Current

func (a *Args) Current() string

Current returns the current argumrnt.

func (*Args) IsLast

func (a *Args) IsLast() bool

IsLast returns true if the index is pointed the last argument.

func (*Args) Next

func (a *Args) Next() *Args

Next returns an immutable Args pointed the next argument. If the index is the last, returns nil.

type Command

type Command struct {
	Name        string
	Description string
	Sub         Completion
}

A Command is the simple completion.

func (*Command) Complete

func (c *Command) Complete(ctx context.Context, args *Args) Reply

Complete returns the pairs that have the prefix of current arg.

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

type Reply map[string]string

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.

type Union

type Union []Completion

Union is the alias of []Completion. It merges replies of each elements.

func (*Union) Complete

func (u *Union) Complete(ctx context.Context, args *Args) Reply

Complete returns the union of replies of all elements.

Directories

Path Synopsis
plugins
zsh

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL