Documentation
¶
Index ¶
- func BindCommand(command *cli.Command, configPointer any, opts ...CommandOption) error
- func Load(configPointer any, programName string, opts ...Option) error
- func LoadArgs(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 MustLoad(configPointer any, programName string, opts ...Option)
- func MustLoadArgs(configPointer any, programName string, args []string, opts ...Option)
- func NewCommand(configPointer any, commandName string, action cli.ActionFunc, ...) (*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 ArgumentMetadata
- type CommandOption
- type ConfigValidator
- type Option
- func WithDefaultLoadConfigFlag() Option
- func WithDescription(description string) Option
- func WithDisableValidation() Option
- func WithLoadConfigFlag(flagName string) Option
- func WithLongDescription(usage string) Option
- func WithShellCompletions() Option
- func WithValidator(validator ConfigValidator) Option
- func WithVersion(version string) Option
- type StructReflector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindCommand ¶ added in v0.2.0
func BindCommand(command *cli.Command, configPointer any, opts ...CommandOption) error
BindCommand binds the given config struct to an existing urfave/cli command.
It appends reflected flags and arguments to the command and wraps the command's Action so that config loading and the configured validator are run before the existing Action.
The WithLoadConfigFlag option is not currently supported for BindCommand/NewCommand.
func Load ¶ added in v0.3.0
Load loads the given config struct.
It loads the config from the following sources in the given order: 1. command line flags and arguments 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 runs the configured validator, which uses the validate tag in config fields by default. The returned error is suitable to be printed to the user.
func LoadArgs ¶ added in v0.3.0
LoadArgs is like Load, but allows explicitly providing the CLI args.
func MarshalAsSlogDict ¶
func MustLoad ¶ added in v0.3.0
MustLoad is like Load, but if it fails, it prints the error to stderr and exits with a non-zero exit code.
func MustLoadArgs ¶ added in v0.3.0
MustLoadArgs is like LoadArgs, 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 ...CommandOption) (*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, arguments, env vars and default values, then the configured validator is run 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 ArgumentMetadata ¶ added in v0.5.0
type CommandOption ¶ added in v0.3.0
type CommandOption func(opts *commandOptions)
func WithCommandValidator ¶ added in v0.3.0
func WithCommandValidator(validator ConfigValidator) CommandOption
func WithDisableCommandValidation ¶ added in v0.3.0
func WithDisableCommandValidation() CommandOption
type ConfigValidator ¶ added in v0.3.0
type Option ¶
type Option func(opts *cliOptions)
func WithDefaultLoadConfigFlag ¶
func WithDefaultLoadConfigFlag() Option
func WithDescription ¶
func WithDisableValidation ¶ added in v0.3.0
func WithDisableValidation() Option
func WithLoadConfigFlag ¶
func WithLongDescription ¶
func WithShellCompletions ¶
func WithShellCompletions() Option
func WithValidator ¶ added in v0.3.0
func WithValidator(validator ConfigValidator) Option
func WithVersion ¶
type StructReflector ¶
type StructReflector interface {
Flags() []cli.Flag
Arguments() []cli.Argument
Apply(*cli.Command)
}
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
|
|
|
10_slices
command
|
|
|
11_arguments
command
|