Documentation ¶
Overview ¶
Package completion - provides a Tree structure that can be used to define a program's completions.
Example Tree:
mygit ├ log │ ├ sublog │ │ ├ --help │ │ ├ <file-completion> │ │ └ <custom-completion (sha1 list)> │ ├ --help │ └ <file-completion> ├ show │ ├ --help │ ├ --dir=<dir-completion> │ └ <file-completion> ├ --help └ --version
A tree node can have children and leaves. The children are commands, the leaves can be options, file completions, custom completions and options that trigger custom file completions (--dir=<dir-comletion>).
Completions have a hierarchy, commands are shown before file completions, and options are only shown if `-` is passed as part of the COMPLINE.
For custom completions a full list of completions must be passed as leaves to the node. However, there file and dir completions are provided as a convenience.
Custom completions for options are triggered with the `=` sing after the full option test has been provided.
Index ¶
- Constants
- Variables
- type Node
- func (n *Node) AddChild(node *Node)
- func (n *Node) CompLineComplete(lastWasOption bool, compLine string) []string
- func (n *Node) Completions(prefix string) []string
- func (n *Node) GetChildByName(name string) *Node
- func (n *Node) GetChildrenByKind(kind kind) []*Node
- func (n *Node) SelfCompletions(prefix string) []string
Constants ¶
const ( // Root - Root kind = iota // CommandNode - Node used to complete the name of the command. CommandNode // FileListNode - Regular file completion you would expect. // Name used as the dir to start completing results from. // TODO: Allow ignore case. FileListNode // OptionsNode - Only enabled if prefix starts with - OptionsNode // OptionsWithCompletion - Only enabled if prefix starts with - OptionsWithCompletion // CustomNode - CustomNode )
Variables ¶
Debug - Debug logger set to io.Discard by default
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct { Name string // Name of the node. For StringNode Kinds, this is the completion. Kind kind // Kind of node. Children []*Node Entries []string // Use as completions for OptionsNode and CustomNode Kind. }
Node -
Example:
mygit ├ log │ ├ sublog │ │ ├ --help │ │ ├ <file-completion> │ │ └ <custom-completion (sha1 list)> │ ├ --help │ └ <file-completion> ├ show │ ├ --help │ ├ --dir=<dir-completion> │ └ <file-completion> ├ --help └ --version
func (*Node) AddChild ¶
AddChild - TODO: Probably make sure that the name is not already in use since we find them by name.
func (*Node) CompLineComplete ¶
CompLineComplete - Given a compLine (get it with os.Getenv("COMP_LINE")) it returns a list of completions.
func (*Node) GetChildByName ¶
GetChildByName - Traverses to the children and returns the first one to match name.
func (*Node) GetChildrenByKind ¶
func (*Node) SelfCompletions ¶
SelfCompletions -