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
- func AddVersion(root *cobra.Command)
- func Args(v cobra.PositionalArgs) cobra.PositionalArgs
- func Execute(root *cobra.Command, stderr io.Writer) int
- func Group(cmd *cobra.Command) *cobra.Command
- func NewVersionCmd(binary string) *cobra.Command
- func Usagef(format string, args ...any) error
- func Version() string
- type UsageError
Constants ¶
const ( ExitOK = 0 ExitFailure = 1 ExitUsage = 2 )
Exit codes of every wpix binary.
Variables ¶
This section is empty.
Functions ¶
func AddVersion ¶
AddVersion gives root the version command and the --version flag, which both print Version alone.
func Args ¶
func Args(v cobra.PositionalArgs) cobra.PositionalArgs
Args wraps a Cobra argument validator so its error is a UsageError.
func Execute ¶
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 ¶
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 ¶
NewVersionCmd is the version command of binary.
func Usagef ¶
Usagef returns a UsageError with a formatted message. A tool package returns it for a usage problem only the tool can detect.
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