Help us shape the future of Go! Take the 2026 Go Developer Survey

cli

package
v0.4.20 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode maps command errors to stable process exit codes: 0 success, 1 runtime failure, 2 usage error.

func IsPresented added in v0.4.11

func IsPresented(err error) bool

func IsTerminal added in v0.4.11

func IsTerminal(w io.Writer) bool

func Presented added in v0.4.11

func Presented(err error) error

func ReportActivityDetail added in v0.4.11

func ReportActivityDetail(w io.Writer, detail string)

ReportActivityDetail updates the human-facing detail of an in-flight Activity when w is the activity progress writer. Other writers intentionally ignore it.

func SuggestClosest added in v0.4.11

func SuggestClosest(input string, candidates []string) string

func WithOutputOptions added in v0.4.11

func WithOutputOptions(ctx context.Context, opts OutputOptions) context.Context

WithOutputOptions attaches process-wide human-output preferences to a command context without changing command result models.

Types

type Command

type Command struct {
	Name     string
	Hidden   bool
	Aliases  []string
	Summary  string
	Usage    string
	Long     string
	Examples []string
	Run      RunFunc
	Children []*Command
}

Command describes one CLI command. Commands can be nested arbitrarily.

func (*Command) Execute

func (c *Command) Execute(ctx context.Context, args []string, out, errOut io.Writer) error

Execute routes args through the command tree and handles help consistently.

func (*Command) Help

func (c *Command) Help(w io.Writer)

Help renders stable, human-readable command documentation.

type OutputOptions added in v0.4.11

type OutputOptions struct {
	Quiet          bool
	Verbose        bool
	NoColor        bool
	ReducedMotion  bool
	Plain          bool
	NonInteractive bool
}

OutputOptions controls human terminal rendering. Machine-readable command output must remain independent from these settings.

func OutputOptionsFromContext added in v0.4.11

func OutputOptionsFromContext(ctx context.Context) OutputOptions

OutputOptionsFromContext returns the current human-output preferences.

type PresentedError added in v0.4.11

type PresentedError struct {
	Err error
}

PresentedError marks a failure that was already rendered as a complete human result by the command. The process must still fail, but main must not append a second generic error block.

func (*PresentedError) Error added in v0.4.11

func (e *PresentedError) Error() string

func (*PresentedError) Unwrap added in v0.4.11

func (e *PresentedError) Unwrap() error

type RunFunc

type RunFunc func(context.Context, []string, io.Writer, io.Writer) error

RunFunc executes a command after command routing and built-in help handling.

type Terminal added in v0.4.11

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

Terminal renders consistent human-facing CLI output. Primary command results still belong on stdout; activity and diagnostics belong on stderr.

func NewTerminal added in v0.4.11

func NewTerminal(ctx context.Context, out, errOut io.Writer) *Terminal

func (*Terminal) Activity added in v0.4.11

func (t *Terminal) Activity(ctx context.Context, label string, fn func(io.Writer) error) error

Activity runs potentially slow work with delayed progress feedback. It never invents percentages or ETAs. Successful buffered detail is shown only in verbose mode; failed detail is always revealed.

func (*Terminal) Diagnostic added in v0.4.11

func (t *Terminal) Diagnostic(format string, args ...any)

func (*Terminal) Fail added in v0.4.11

func (t *Terminal) Fail(label, detail string)

func (*Terminal) Header added in v0.4.11

func (t *Terminal) Header(app, environment string)

func (*Terminal) Info added in v0.4.11

func (t *Terminal) Info(label, detail string)

func (*Terminal) NonInteractive added in v0.4.11

func (t *Terminal) NonInteractive() bool

func (*Terminal) Plain added in v0.4.11

func (t *Terminal) Plain() bool

func (*Terminal) Quiet added in v0.4.11

func (t *Terminal) Quiet() bool

func (*Terminal) Result added in v0.4.11

func (t *Terminal) Result(state, subject, detail string)

func (*Terminal) Section added in v0.4.11

func (t *Terminal) Section(title string)

func (*Terminal) Skip added in v0.4.11

func (t *Terminal) Skip(label, detail string)

func (*Terminal) Success added in v0.4.11

func (t *Terminal) Success(label, detail string)

func (*Terminal) TTY added in v0.4.11

func (t *Terminal) TTY() bool

func (*Terminal) Verbose added in v0.4.11

func (t *Terminal) Verbose() bool

func (*Terminal) Warn added in v0.4.11

func (t *Terminal) Warn(label, detail string)

type UsageError

type UsageError struct {
	Message string
	Hint    string
}

UsageError represents invalid user input. Callers should exit with code 2.

func (*UsageError) Error

func (e *UsageError) Error() string

Jump to

Keyboard shortcuts

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