Documentation
¶
Overview ¶
Package climate "CLI Mate" provides a set of APIs to autogenerate CLIs from structs/functions with support for nested subcommands, global/local flags, help generation from comments, typo suggestions, shell completion and more.
See https://github.com/avamsi/climate/blob/main/README.md for more details.
Index ¶
- func ErrExit(code int, errs ...error) *exitError
- func ErrUsage(err error) *usageError
- func Func(f any) *funcPlan
- func Run(ctx context.Context, p internal.Plan, mods ...func(*internal.RunOptions)) int
- func RunAndExit(p internal.Plan, mods ...func(*internal.RunOptions))
- func Struct[T any](subcommands ...*structPlan) *structPlan
- func WithMetadata(b []byte) func(*internal.RunOptions)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrExit ¶
ErrExit returns an exitError with the given exit code and errors. exitError is used to indicate that the CLI should exit with the given exit code (as returned by Run and respected by RunAndExit).
func ErrUsage ¶
func ErrUsage(err error) *usageError
ErrUsage returns the given error wrapped in a usageError or nil otherwise. usageError is used to indicate there's something wrong with the user input and that the usage information should be printed along with the error.
func Func ¶
func Func(f any) *funcPlan
Func returns an executable plan for the given function, which must conform to the following signatures (excuse the partial [optional] notation):
func([ctx context.Context], [opts *T], [args []string]) [(err error)]
All of ctx, opts, args and error are optional. If opts is present, T must be a struct (whose fields are used as flags).
func RunAndExit ¶
func RunAndExit(p internal.Plan, mods ...func(*internal.RunOptions))
RunAndExit executes the given plan and exits with the exit code.
func Struct ¶
func Struct[T any](subcommands ...*structPlan) *structPlan
Struct returns an executable plan for the struct given as the type parameter, with its methods* (and "child" structs) as subcommands.
* Only methods with pointer receiver are considered (and they must otherwise conform to the same signatures described in Func).
func WithMetadata ¶
func WithMetadata(b []byte) func(*internal.RunOptions)
WithMetadata returns a modifier that sets the metadata to be used by Run for augmenting the CLI with additional information (for --help etc.).
Types ¶
This section is empty.