cli

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: ISC Imports: 9 Imported by: 0

Documentation

Overview

Package cli contains common command-line flags and configuration options.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExitVersion is an error indicating the application should exit after
	// showing version.
	ErrExitVersion = &unprintableError{errors.New("version flag exit")}
	// ErrInvalidArgs indicates that the command-line arguments provided to the
	// application are invalid or insufficient. This error should be wrapped with
	// fmt.Errorf to provide a specific, user-friendly message explaining the
	// nature of the invalid arguments. For example:
	//
	// 	return fmt.Errorf("%w: missing required argument 'filename'", cli.ErrInvalidArgs)
	//
	ErrInvalidArgs = errors.New("invalid arguments")
)

Functions

func Run added in v0.3.0

func Run(f func(ctx context.Context) error)

Run executes the provided function f within a context that is canceled when an interrupt signal (e.g., Ctrl+C) is received.

If f returns a non-nil error, Run prints the error message to standard error (if the error is considered "printable") and exits the program with a status code of 1.

Printable errors are those that provide useful information to the user. Errors like flag parsing errors or help requests are considered non-printable and are not displayed to the user.

Types

type App added in v0.3.0

type App struct {
	Name        string        // Name of the application.
	Description string        // Description of the application.
	ArgsUsage   string        // Usage message for the command-line arguments.
	Flags       *flag.FlagSet // Command-line flags.
}

App represents a command-line application.

func (*App) HandleStartup added in v0.3.0

func (a *App) HandleStartup(args []string, stdout, stderr io.Writer) error

HandleStartup handles the command startup. All exported fields shouldn't be modified after HandleStartup is called.

It sets up the command-line flags, parses the arguments, and handles the version flag if specified.

Jump to

Keyboard shortcuts

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