carapace

package module
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

README

carapace

CircleCI PkgGoDev documentation GoReportCard Docker Cloud Automated build

Completion script generator for cobra with support for:

Status

WIP: works, but expect some api changes and small hiccups like a special character not yet escaped

Usage

Calling carapace.Gen on any command is sufficient to enable completion script generation using the hidden command.

import (
    "github.com/rsteube/carapace"
)

carapace.Gen(myCmd)

Standalone Mode

Carapace can also be used to provide completion for arbitrary commands as well (similar to aws_completer). See rsteube/carapace-bin for examples. There is also a binary to parse flags from gnu help pages at caraparse.

Example

An example implementation can be found in the example folder.

cd example
go build .

# bash
PATH=$PATH:$(pwd)
source <(example _carapace bash)

# elvish
paths=[$@paths (pwd)]
eval (example _carapace elvish | slurp)

# fish
set PATH $PATH (pwd) 
example _carapace fish | source

# oil
PATH=$PATH:$(pwd)
source <(example _carapace oil)

# powershell
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
$env:PATH += ":$pwd"
example _carapace powershell | out-string | Invoke-Expression

# xonsh
$PATH.append($(pwd))
exec($(example _carapace xonsh))

# zsh
PATH=$PATH:$(pwd)
source <(example _carapace zsh)

example <TAB>

or use docker-compose:

docker-compose pull
docker-compose run --rm build
docker-compose run --rm [bash|elvish|fish|oil|powershell|xonsh|zsh]

example <TAB>

Projects

  • carapace-bin multi-shell multi-command argument completer
  • gh github cli with added completions (fork)
  • lab cli client for GitLab

Documentation

Overview

Package carapace provides multi-shell completion script generation for spf13/cobra

Index

Constants

This section is empty.

Variables

View Source
var CallbackValue string

CallbackValue is set to the currently completed flag/positional value during callback (note that this is updated during ActionMultiParts)

Functions

func IsCallback added in v0.0.6

func IsCallback() bool

Types

type Action

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

Action indicates how to complete a flag or positional argument

func ActionBool

func ActionBool() Action

ActionBool completes true/false

func ActionCallback

func ActionCallback(callback CompletionCallback) Action

ActionCallback invokes a go function during completion

func ActionDirectories added in v0.0.11

func ActionDirectories() Action

ActionDirectories completes directories

func ActionFiles

func ActionFiles(suffix string) Action

ActionFiles completes files with optional suffix filtering

func ActionMessage

func ActionMessage(msg string) Action

ActionMessage displays a help messages in places where no completions can be generated

func ActionMultiParts

func ActionMultiParts(divider string, callback func(args []string, parts []string) Action) Action

ActionMultiParts completes multiple parts of words separately where each part is separated by some char (CallbackValue is set to the currently completed part during invocation)

func ActionValues

func ActionValues(values ...string) Action

ActionValues completes arbitrary keywords (values)

func ActionValuesDescribed

func ActionValuesDescribed(values ...string) Action

ActionValuesDescribed completes arbitrary key (values) with an additional description (value, description pairs)

func (Action) Cache added in v0.2.4

func (a Action) Cache(timeout time.Duration, keys ...pkgcache.CacheKey) Action

func (Action) Invoke added in v0.1.1

func (a Action) Invoke(args []string) InvokedAction

Invoke executes the callback of an action if it exists (supports nesting)

func (Action) Value added in v0.0.8

func (a Action) Value(shell string) string

type ActionMap

type ActionMap map[string]Action

type Carapace

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

func Gen

func Gen(cmd *cobra.Command) *Carapace

func (Carapace) FlagCompletion

func (c Carapace) FlagCompletion(actions ActionMap)

func (Carapace) PositionalAnyCompletion added in v0.0.14

func (c Carapace) PositionalAnyCompletion(action Action)

func (Carapace) PositionalCompletion

func (c Carapace) PositionalCompletion(action ...Action)

func (Carapace) Snippet added in v0.0.6

func (c Carapace) Snippet(shell string) (string, error)

func (Carapace) Standalone added in v0.0.14

func (c Carapace) Standalone()

type CompletionCallback

type CompletionCallback func(args []string) Action

type InvokedAction added in v0.1.1

type InvokedAction Action

func (InvokedAction) Filter added in v0.1.1

func (a InvokedAction) Filter(values []string) InvokedAction

func (InvokedAction) Merge added in v0.1.8

func (a InvokedAction) Merge(others ...InvokedAction) InvokedAction

func (InvokedAction) Prefix added in v0.1.1

func (a InvokedAction) Prefix(prefix string) InvokedAction

func (InvokedAction) Suffix added in v0.1.1

func (a InvokedAction) Suffix(suffix string) InvokedAction

func (InvokedAction) ToA added in v0.1.1

func (a InvokedAction) ToA() Action

func (InvokedAction) ToMultiPartsA added in v0.2.2

func (a InvokedAction) ToMultiPartsA(divider string) Action

Directories

Path Synopsis
cmd
internal
oil
uid
zsh
pkg

Jump to

Keyboard shortcuts

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