Documentation
¶
Index ¶
- func BindCommand(command *cli.Command, configPointer any, opts ...Option) error
- func LoadAndValidate(configPointer any, programName string, opts ...Option) error
- func LoadAndValidateArgs(configPointer any, programName string, args []string, opts ...Option) error
- func MarshalAsMap(configPointer any) (map[string]any, error)
- func MarshalAsSlogDict(configPointer any, groupName string) (slog.Attr, error)
- func MustLoadAndValidate(configPointer any, programName string, opts ...Option)
- func MustLoadAndValidateArgs(configPointer any, programName string, args []string, opts ...Option)
- func NewCommand(configPointer any, commandName string, action cli.ActionFunc, opts ...Option) (*cli.Command, error)
- func NewMapSource(name string, m map[any]any) cli.MapSource
- func NewTomlFileSource(name string, file string) (cli.MapSource, error)
- func NewValueSourceFromMaps(key string, sources ...cli.MapSource) cli.ValueSource
- type Option
- type StructReflector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindCommand ¶ added in v0.2.0
BindCommand binds the given config struct to an existing urfave/cli command.
It appends reflected flags to the command and wraps the command's Action so that config loading and validation are run before the existing Action.
The WithLoadConfigFlag option is not currently supported for BindCommand/NewCommand.
func LoadAndValidate ¶
LoadAndValidate loads the given config struct and validates it.
It loads the config from the following sources in the given order: 1. command line flags 2. config files (if the config struct satisfies the loadConfigFromTOMLFiles interface by embedding LoadTOMLConfig) 3. environment variables 4. default values defined in the field tags
It then validates the loaded config, using the validate tag in config fields - if it fails, it returns an error. The returned error is suitable to be printed to the user.
func LoadAndValidateArgs ¶ added in v0.2.0
func LoadAndValidateArgs(configPointer any, programName string, args []string, opts ...Option) error
LoadAndValidateArgs is like LoadAndValidate, but allows explicitly providing the CLI args.
func MarshalAsSlogDict ¶
func MustLoadAndValidate ¶
MustLoadAndValidate is like LoadAndValidate, but if it fails, it prints the error to stderr and exits with a non-zero exit code.
func MustLoadAndValidateArgs ¶ added in v0.2.0
MustLoadAndValidateArgs is like LoadAndValidateArgs, but if it fails, it prints the error to stderr and exits with a non-zero exit code.
func NewCommand ¶ added in v0.2.0
func NewCommand(configPointer any, commandName string, action cli.ActionFunc, opts ...Option) (*cli.Command, error)
NewCommand creates a urfave/cli command and binds the given config struct to it.
When the command is executed, the config is loaded from flags, env vars and default values, then validated before the optional action is executed.
The WithLoadConfigFlag option is not currently supported for BindCommand/NewCommand.
func NewValueSourceFromMaps ¶
func NewValueSourceFromMaps(key string, sources ...cli.MapSource) cli.ValueSource
Types ¶
type Option ¶
type Option func(opts *options)
func WithDefaultLoadConfigFlag ¶
func WithDefaultLoadConfigFlag() Option
func WithDescription ¶
func WithLoadConfigFlag ¶
func WithLongDescription ¶
func WithShellCompletions ¶
func WithShellCompletions() Option
func WithVersion ¶
type StructReflector ¶
func NewStructConfigurator ¶
func NewStructConfigurator(anyStruct any, tomlSources []cli.MapSource) (StructReflector, error)
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
01_simple_cli
command
|
|
|
02_default_values
command
|
|
|
03_nested
command
|
|
|
04_toml
command
|
|
|
05_override
command
|
|
|
06_global
command
|
|
|
07_marshal
command
|
|
|
08_validation
command
|
|
|
09_subcommands
command
|