cli

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package cli holds what the command-line programs (backupd, takeout, decrypt, install-bundle) agree on: how flags are parsed and what the exit status means.

Exit status:

0  success, and asking for help (-h)
1  the program ran and failed (wrong key, unreachable store, bad
   configuration in the environment)
2  the command line was wrong (unknown flag or command, a missing
   required flag, a stray argument); nothing was attempted

The package never exits and never writes to the process's own streams; it is handed the writers, so every path is testable.

Index

Constants

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

Exit statuses.

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode is the exit status for the outcome err.

func IsUsage

func IsUsage(err error) bool

IsUsage reports whether err is a usage error or a request for help, i.e. something that is about the command line rather than the work.

func Parse

func Parse(fs *flag.FlagSet, args []string, stdout, stderr io.Writer) error

Parse parses args into fs. None of these programs takes positional arguments, so one is refused rather than silently ignored.

Asked for help (-h, -help), it writes the usage text to stdout, because that is the output asked for, and returns flag.ErrHelp. A malformed command line has its error and the usage text written to stderr and comes back as a *UsageError.

func Report

func Report(stderr io.Writer, program string, err error) int

Report writes err to stderr the way a person at a terminal reads it, unless it was written already or is a request for help, and returns the exit status. program is what the user typed, e.g. "backupd rotate-srw"; a usage error ends with a pointer to its help.

func Usagef

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

Usagef reports a command line that cannot be acted on.

Types

type UsageError

type UsageError struct {
	Err error
	// contains filtered or unexported fields
}

UsageError is a command line that cannot be acted on. Nothing was attempted, and running the same thing again will fail the same way.

func (*UsageError) Error

func (e *UsageError) Error() string

func (*UsageError) Unwrap

func (e *UsageError) Unwrap() error

Jump to

Keyboard shortcuts

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