Documentation
¶
Index ¶
Constants ¶
const ErrUsage = ErrExitCode(2)
ErrUsage indicates an error in command usage; e.g. unknown flags, subcommands or args. It corresponds to exit code 2.
Variables ¶
This section is empty.
Functions ¶
func AddEnvToContext ¶
AddEnvToContext returns a new Context with the `env` added to it.
func ExitCode ¶
func ExitCode(err error, w io.Writer) subcommands.ExitStatus
ExitCode returns the exit code corresponding to err.
0: if err == nil code: if err is ErrExitCode(code) 1: all other errors
Writes the error message for "all other errors" to w, if w is non-nil.
func Main ¶
func Main(env *Env, commander *subcommands.Commander) subcommands.ExitStatus
Main implements the main function for the given commander.
Types ¶
type Env ¶
type Env struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
Vars map[string]string // Environment variables
Timer *timing.Timer
// WorkingDir overrides the process working directory when resolving paths.
WorkingDir string
// Usage is a function that prints usage information to w. Typically set by
// calls to Main or Parse to print usage of the leaf command.
Usage func(ctx context.Context, w io.Writer)
// Comamnd name
CommandName string
// command flags
CommandFlags map[string]string
}
Env represents the environment for command parsing and running. Typically EnvFromOS is used to produce a default environment. The environment may be explicitly set for finer control; e.g. in tests.
func EnvFromContext ¶
EnvFromContext retrieves the Env from the given Context.
func EnvFromOS ¶
func EnvFromOS() *Env
EnvFromOS returns a new environment based on the operating system.
func (*Env) TimerPop ¶
func (e *Env) TimerPop()
TimerPop calls e.Timer.Pop(), only if the Timer is non-nil.
type ErrExitCode ¶
type ErrExitCode int
ErrExitCode may be returned by Runner.Run to cause the program to exit with a specific error code.
func (ErrExitCode) Error ¶
func (x ErrExitCode) Error() string
Error implements the error interface method.