comp

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 24

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	CmdsOpts               = Combine{Cmds, Opts}
	CmdsAliases            = Combine{Cmds, Aliases}
	CmdsAliasesOpts        = Combine{Cmds, Aliases, Opts}
	FileDirCmdsOpts        = Combine{FileDir, CmdsOpts}
	FileDirCmdsAliasesOpts = Combine{FileDir, CmdsAliasesOpts}
)
View Source
var Aliases = new(aliases)

Aliases is a bonzai.Completer for all available bonzai.Cmd.Aliases including bonzai.Cmd.Name.

View Source
var Cmds = new(cmds)

Cmds is a bonzai.Completer for all available bonzai.Cmd.Cmds. It excludes hidden commands.

View Source
var FileDir = fileDir{}

FileDir is a bonzai.Completer that completes for file names. This [Completer] is roughly based on the behavior of the bash shell with forward slashes as separators and escaped spaces. By using this completer (instead of the shell) the command line interface remains consistent across all runtimes. Note that unlike bash completion no indication of the type of file is provided (i.e. dircolors support).

View Source
var Opts = new(opts)

Opts is a bonzai.Completer for all available bonzai.Cmd.Opts.

Functions

This section is empty.

Types

type Combine

type Combine []any
Example (Transform)
package main

import (
	"fmt"

	"github.com/rwxrob/bonzai"
	"github.com/rwxrob/bonzai/comp"
	"github.com/rwxrob/bonzai/fn/tr"
)

func main() {

	foo := &bonzai.Cmd{
		Name: `foo`,
		Opts: `box`,
		Comp: comp.Combine{comp.CmdsOpts, tr.Prefix{`aprefix`}},
		Cmds: []*bonzai.Cmd{{Name: `bar`}, {Name: `blah`}},
	}

	foo.Comp.(bonzai.CmdCompleter).SetCmd(foo)

	// we know it's not a command, but no prefix just yet
	// (usually this is when a space has been added after the command)
	fmt.Println(foo.Comp.Complete(""))

	// everything that begins with a (nothing)
	fmt.Println(foo.Comp.Complete(`a`))

	// everything that begins with b (which is everything)
	fmt.Println(foo.Comp.Complete(`b`))

	// everything that begins with bl (just blah)
	fmt.Println(foo.Comp.Complete(`bl`))

}
Output:

[aprefixbar aprefixblah aprefixbox]
[]
[aprefixbar aprefixblah aprefixbox]
[aprefixblah]

func (Combine) Cmd added in v0.6.0

func (Combine) Cmd() *bonzai.Cmd

func (Combine) Complete

func (ops Combine) Complete(args ...string) []string

func (Combine) SetCmd added in v0.6.0

func (Combine) SetCmd(a *bonzai.Cmd)

type Env added in v0.10.0

type Env struct {
	// Prefix is prepended to the environment variable search.
	// For example, if Prefix is "APP_", only environment variables
	// starting with "APP_" will be included in completions.
	Prefix string

	// Insensitive determines if case-insensitive matching should be used.
	// When true, "path" will match "PATH", "Path", "path", etc.
	Insensitive bool
}

Env defines the configuration for environment variable completion.

func (Env) Complete added in v0.10.0

func (c Env) Complete(args ...string) []string

Directories

Path Synopsis
completers
git Module

Jump to

Keyboard shortcuts

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