completion

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MPL-2.0 Imports: 7 Imported by: 0

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

View Source
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

View Source
var Debug = log.New(io.Discard, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile)

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 NewNode

func NewNode(name string, kind kind, entries []string) *Node

NewNode -

func (*Node) AddChild

func (n *Node) AddChild(node *Node)

AddChild - TODO: Probably make sure that the name is not already in use since we find them by name.

func (*Node) CompLineComplete

func (n *Node) CompLineComplete(lastWasOption bool, compLine string) []string

CompLineComplete - Given a compLine (get it with os.Getenv("COMP_LINE")) it returns a list of completions.

func (*Node) Completions

func (n *Node) Completions(prefix string) []string

Completions -

func (*Node) GetChildByName

func (n *Node) GetChildByName(name string) *Node

GetChildByName - Traverses to the children and returns the first one to match name.

func (*Node) GetChildrenByKind

func (n *Node) GetChildrenByKind(kind kind) []*Node

func (*Node) SelfCompletions

func (n *Node) SelfCompletions(prefix string) []string

SelfCompletions -

Jump to

Keyboard shortcuts

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