ffcomplete

package
v1.67.0-pre Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package ffcomplete provides shell tab-completion of subcommands, flags and arguments for Go programs written with ffcli.

The shell integration scripts have been extracted from Cobra (https://cobra.dev/), whose authors deserve most of the credit for this work. These shell completion functions invoke `$0 completion __complete -- ...` which is wired up to [Complete].

Index

Constants

View Source
const (
	ShellCompDirectiveError         = cobra.ShellCompDirectiveError
	ShellCompDirectiveNoSpace       = cobra.ShellCompDirectiveNoSpace
	ShellCompDirectiveNoFileComp    = cobra.ShellCompDirectiveNoFileComp
	ShellCompDirectiveFilterFileExt = cobra.ShellCompDirectiveFilterFileExt
	ShellCompDirectiveFilterDirs    = cobra.ShellCompDirectiveFilterDirs
	ShellCompDirectiveKeepOrder     = cobra.ShellCompDirectiveKeepOrder
	ShellCompDirectiveDefault       = cobra.ShellCompDirectiveDefault
)

Variables

This section is empty.

Functions

func Args

func Args(cmd *ffcli.Command, comp CompleteFunc)

Args registers a completion function for the args of cmd.

comp will be called to return suggestions when the user tries to tab-complete `prog <TAB>` or `prog subcmd arg1 <TAB>`, for example.

func Flag

func Flag(fs *flag.FlagSet, name string, comp CompleteFunc)

Flag registers a completion function for the flag in fs with given name. comp will always called with a 1-element slice.

comp will be called to return suggestions when the user tries to tab-complete '--name=<TAB>' or '--name <TAB>' for the commands using fs.

func Inject

func Inject(root *ffcli.Command, hide func(*ffcli.Command), usageFunc func(*ffcli.Command) string)

Inject adds the 'completion' subcommand to the root command which provide the user with shell scripts for calling `completion __command` to provide tab-completion suggestions.

root.Name needs to match the command that the user is tab-completing for the shell script to work as expected by default.

The hide function is called with the __complete Command instance to provide a hook to omit it from the help output, if desired.

func LastArg

func LastArg(args []string) string

LastArg returns the last element of args, or the empty string if args is empty.

Types

type CompleteFunc

type CompleteFunc = internal.CompleteFunc

CompleteFunc is used to return tab-completion suggestions to the user as they are typing command-line instructions. It returns the list of things to suggest and an additional directive to the shell about what extra functionality to enable.

func FilesWithExtensions

func FilesWithExtensions(exts ...string) CompleteFunc

FilesWithExtensions returns a CompleteFunc that tells the shell to limit file suggestions to those with the given extensions.

func Fixed

func Fixed(words ...string) CompleteFunc

Fixed returns a CompleteFunc which suggests the given words.

type ShellCompDirective

type ShellCompDirective = cobra.ShellCompDirective

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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