Documentation
¶
Index ¶
- Variables
- func EnvVarsArrayToMap(envVars []string) map[string]string
- func SetupSignalHandler() context.Context
- type Action
- type ActionFunc
- type Command
- type ErrInvalidTag
- type ErrInvalidValue
- type ErrRequiredFlagMissing
- type ErrUnknownFlag
- type ExitCode
- type HelpConfig
- type PostRunHook
- type PostRunHookFunc
- type PreRunHook
- type PreRunHookFunc
- type Tag
- type WrappingWriter
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidCommand = errors.New("invalid command") ErrCommandAlreadyHasParent = errors.New("command already has a parent") )
Functions ¶
func EnvVarsArrayToMap ¶
func SetupSignalHandler ¶ added in v0.0.2
SetupSignalHandler registers for SIGTERM and SIGINT. A context is returned which is canceled on one of these signals. If a second signal is caught, the program is terminated with exit code 1.
Types ¶
type ActionFunc ¶ added in v0.4.0
type Command ¶
type Command struct { HelpConfig *HelpConfig // contains filtered or unexported fields }
Command is a command instance, created by New and can be composed with more Command instances to form a CLI command hierarchy.
func MustNew ¶ added in v0.3.0
func MustNew(name, shortDescription, longDescription string, action Action, hooks []any, subCommands ...*Command) *Command
MustNew creates a new command using New, but will panic if it returns an error.
func New ¶
func New(name, shortDescription, longDescription string, action Action, hooks []any, subCommands ...*Command) (*Command, error)
New creates a new command with the given name, short & long descriptions, and the given executor. The executor object is also scanned for configuration structs via reflection.
func (*Command) AddSubCommand ¶ added in v0.3.0
AddSubCommand will add the given command as a sub-command of this command. An error is returned if the given command already has another parent.
type ErrInvalidTag ¶ added in v0.3.0
func (*ErrInvalidTag) Error ¶ added in v0.3.0
func (e *ErrInvalidTag) Error() string
func (*ErrInvalidTag) Unwrap ¶ added in v0.3.0
func (e *ErrInvalidTag) Unwrap() error
type ErrInvalidValue ¶ added in v0.3.0
func (*ErrInvalidValue) Error ¶ added in v0.3.0
func (e *ErrInvalidValue) Error() string
func (*ErrInvalidValue) Unwrap ¶ added in v0.3.0
func (e *ErrInvalidValue) Unwrap() error
type ErrRequiredFlagMissing ¶ added in v0.3.0
func (*ErrRequiredFlagMissing) Error ¶ added in v0.3.0
func (e *ErrRequiredFlagMissing) Error() string
func (*ErrRequiredFlagMissing) Unwrap ¶ added in v0.3.0
func (e *ErrRequiredFlagMissing) Unwrap() error
type ErrUnknownFlag ¶ added in v0.3.0
func (*ErrUnknownFlag) Error ¶ added in v0.3.0
func (e *ErrUnknownFlag) Error() string
func (*ErrUnknownFlag) Unwrap ¶ added in v0.3.0
func (e *ErrUnknownFlag) Unwrap() error
type ExitCode ¶ added in v0.3.0
type ExitCode int
func Execute ¶
Execute the correct command in the given command hierarchy (starting at "root"), configured from the given CLI args and environment variables. The command will be executed with a context that gets canceled when an OS signal for termination is received, after all pre-RunFunc hooks have been successfully executed in the command hierarchy.
func ExecuteWithContext ¶ added in v0.7.0
func ExecuteWithContext(ctx context.Context, w io.Writer, root *Command, args []string, envVars map[string]string) (exitCode ExitCode)
ExecuteWithContext the correct command in the given command hierarchy (starting at "root"), configured from the given CLI args and environment variables. The command will be executed with the given context after all pre-RunFunc hooks have been successfully executed in the command hierarchy.
type HelpConfig ¶ added in v0.3.0
type HelpConfig struct {
Help bool `inherited:"true" desc:"Show this help screen and exit."`
}
HelpConfig is a configuration added to every executed command, for automatic help screen generation.
type PostRunHook ¶ added in v0.5.0
type PostRunHookFunc ¶ added in v0.5.0
type PreRunHook ¶ added in v0.4.0
type PreRunHookFunc ¶ added in v0.4.0
type WrappingWriter ¶ added in v0.3.0
type WrappingWriter struct {
// contains filtered or unexported fields
}
func NewWrappingWriter ¶ added in v0.3.0
func NewWrappingWriter(width int) (*WrappingWriter, error)
func (*WrappingWriter) SetLinePrefix ¶ added in v0.3.0
func (w *WrappingWriter) SetLinePrefix(prefix string) error
func (*WrappingWriter) String ¶ added in v0.3.0
func (w *WrappingWriter) String() string