cli

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ErrCompletionRequested = errors.Sentinel("ErrCompletionRequested")

ErrCompletionRequested is a sentinel error indicating that the command was invoked in completion mode and that the completion options should be printed out instead of running the command

View Source
const ErrCompletionScriptRequested = errors.Sentinel("ErrCompletionScriptRequested")

ErrCompletionScriptRequested is a sentinel error indicating the bash completion script was requested and should be printed to stdout for evaluation

View Source
const ErrHelpRequested = errors.Sentinel("ErrHelpRequested")

ErrHelpRequested is a sentinel error indicating that help was requested with no explicit flag to handle the request

View Source
const ErrVersionRequested = errors.Sentinel("ErrVersionRequested")

ErrVersionRequested is a sentinel error indicating that version was requested with no explicit flag to handle the request

Variables

This section is empty.

Functions

func BashCompletionScript

func BashCompletionScript(command string) string

BashCompletionScript returns a string containing the bash script necessary to setup bash completion for the command.

func DefaultCompletion

func DefaultCompletion(opt *option.T, w string) []string

DefaultCompletion implements a default completion for a given option field, and can be used a fallback by command completion handlers. It handles specific cases based on the option field type, and simulates default shell behavior (filename completion) for string types.

func DefaultFilenameCompletion added in v0.5.0

func DefaultFilenameCompletion(opt *option.T, w string) (r []string)

DefaultFilenameCompletion implements a default filename-based completion, similar to the default shell completion.

func MatchingFilenameCompletion added in v0.5.0

func MatchingFilenameCompletion(opt *option.T, pattern string, w string) (r []string)

MatchingFileCompletion implements a custom filepath completion scheme, matching the provided pattern if possible, using default filename completion as a fallback.

Types

type Command

type Command struct {
	Handler     Handler
	Description string

	ProcessName       string
	ProcessArgs       []string
	ProcessEnv        map[string]string
	ConsoleWidth      int
	DisableCompletion bool

	Suggestions []string
	// contains filtered or unexported fields
}

Command is the representation of a runnable command, with reference to a runnable command attached to an options struct

func (*Command) Run

func (cmd *Command) Run() error

Run is the main invocation point for a command. The command must be seeded with all the necessary runtime arguments from the process context (`ProcessName`, `ProcessArgs`, `ProcessEnv` and `ConsoleWidth`). It sets up the command option struct, applies the defaults abd environment variable, decodes the command-line and run the command.

func (*Command) SetProcessEnv

func (cmd *Command) SetProcessEnv(env []string)

SetProcessEnv sets the command `ProcessEnv` from a list of environment strings as returned by os.Environ().

func (*Command) Usage

func (cmd *Command) Usage() string

Usage returns a string containign the usage for the command. The display name for the command is expected as first argument.

func (*Command) Version

func (cmd *Command) Version() (version string)

Version returns a version string for the command

type CompletionHandler

type CompletionHandler interface {
	Complete(opt *option.T, partial string) []string
}

CompletionHandler is an optional interface for the command handler to provide meaningful values for a specific option or argument.

type Handler

type Handler interface {
	Run() error
}

Handler defines the interface necessary to run a command once the command lien arguments have been parsed

type UsageHandler

type UsageHandler interface {
	Usage(name string, width int) string
}

UsageHandler defines an optional interface for the command handler to print a custom usage message

type VersionHandler

type VersionHandler interface {
	Version() string
}

VersionHandler defines an optional interface for the command handler to return a relevant version string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳