Documentation ¶
Overview ¶
Package complete provides a tool for bash writing bash completion in go.
Writing bash completion scripts is a hard work. This package provides an easy way to create bash completion scripts for any command, and also an easy way to install/uninstall the completion of the command.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Log = getLogger()
Log is used for debugging purposes since complete is running on tab completion, it is nice to have logs to the stderr (when writing your own completer) to write logs, set the COMP_DEBUG environment variable and use complete.Log in the complete program
var PredictAnything = PredictFunc(func(Args) []string { return nil })
PredictAnything expects something, but nothing particular, such as a number or arbitrary name.
Functions ¶
This section is empty.
Types ¶
type Args ¶
type Args struct { // All lists of all arguments in command line (not including the command itself) All []string // Completed lists of all completed arguments in command line, // If the last one is still being typed - no space after it, // it won't appear in this list of arguments. Completed []string // Last argument in command line, the one being typed, if the last // character in the command line is a space, this argument will be empty, // otherwise this would be the last word. Last string // LastCompleted is the last argument that was fully typed. // If the last character in the command line is space, this would be the // last word, otherwise, it would be the word before that. LastCompleted string }
Args describes command line arguments
type Command ¶
type Command struct { // Sub is map of sub commands of the current command // The key refer to the sub command name, and the value is it's // Command descriptive struct. Sub Commands // Flags is a map of flags that the command accepts. // The key is the flag name, and the value is it's predictions. Flags Flags // GlobalFlags is a map of flags that the command accepts. // Global flags that can appear also after a sub command. GlobalFlags Flags // Args are extra arguments that the command accepts, those who are // given without any flag before. Args Predictor }
Command represents a command line It holds the data that enables auto completion of command line Command can also be a sub command.
type Complete ¶
Complete structs define completion for a command with CLI options
func New ¶
New creates a new complete command. name is the name of command we want to auto complete. IMPORTANT: it must be the same name - if the auto complete completes the 'go' command, name must be equal to "go". command is the struct of the command completion.
func (*Complete) Complete ¶
Complete a command from completion line in environment variable, and print out the complete options. returns success if the completion ran or if the cli matched any of the given flags, false otherwise For installation: it assumes that flags were added and parsed before it was called.
type Flags ¶
Flags is the type Flags of the Flags member, it maps a flag name to the flag predictions.
type PredictFunc ¶
PredictFunc determines what terms can follow a command or a flag It is used for auto completion, given last - the last word in the already in the command line, what words can complete it.
func PredictFilesSet ¶
func PredictFilesSet(files []string) PredictFunc
PredictFilesSet predict according to file rules to a given set of file names
func (PredictFunc) Predict ¶
func (p PredictFunc) Predict(a Args) []string
Predict invokes the predict function and implements the Predictor interface
type Predictor ¶
Predictor implements a predict method, in which given command line arguments returns a list of options it predicts.
var PredictNothing Predictor
PredictNothing does not expect anything after.
func PredictDirs ¶
PredictDirs will search for directories in the given started to be typed path, if no path was started to be typed, it will complete to directories in the current working directory.
func PredictFiles ¶
PredictFiles will search for files matching the given pattern in the started to be typed path, if no path was started to be typed, it will complete to files that match the pattern in the current working directory. To match any file, use "*" as pattern. To match go files use "*.go", and so on.
func PredictOr ¶
PredictOr unions two predicate functions, so that the result predicate returns the union of their predication
func PredictSet ¶
PredictSet expects specific set of terms, given in the options argument.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package cmd used for command line options for the complete tool
|
Package cmd used for command line options for the complete tool |
example
|
|
self
Package self a program that complete itself
|
Package self a program that complete itself |
Package main is complete tool for the go command line
|
Package main is complete tool for the go command line |