cli

package
v0.0.0-...-2d09b37 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cli is what the Cobra command trees of the wpix binaries share: the exit codes (0 ok, 1 failure, 2 usage), the error type that means a usage error, and the version command. Tool packages import only UsageError and Usagef from here; Cobra stays in the cmd packages.

Index

Constants

View Source
const (
	ExitOK      = 0
	ExitFailure = 1
	ExitUsage   = 2
)

Exit codes of every wpix binary.

Variables

This section is empty.

Functions

func AddVersion

func AddVersion(root *cobra.Command)

AddVersion gives root the version command and the --version flag, which both print Version alone.

func Args

Args wraps a Cobra argument validator so its error is a UsageError.

func Execute

func Execute(root *cobra.Command, stderr io.Writer) int

Execute runs root and returns the exit code: 0 on success, 2 for a UsageError, a flag that does not parse, a wrong argument count or a missing required flag, 1 for any other error. An error is printed to stderr as "<command path>: <error>", without the usage text. Output of --help goes where the caller pointed root.SetOut, stdout by default.

func Group

func Group(cmd *cobra.Command) *cobra.Command

Group makes cmd a command that only has subcommands: with no subcommand it prints its help to stderr and is a usage error, with an unknown one it is a usage error naming it.

func NewVersionCmd

func NewVersionCmd(binary string) *cobra.Command

NewVersionCmd is the version command of binary.

func Usagef

func Usagef(format string, args ...any) error

Usagef returns a UsageError with a formatted message. A tool package returns it for a usage problem only the tool can detect.

func Version

func Version() string

Version is the module version of the binary: a release or pseudo-version when installed with go install or go run pkg@version, "(devel)" from a checkout.

Types

type UsageError

type UsageError struct{ Msg string }

UsageError is an error that makes the command exit with ExitUsage: the command line was wrong, not the work it did.

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