Documentation
¶
Index ¶
- Variables
- func Exit(err error)
- func ExitWithMessage(err error)
- func Hydrate[T any](ctx context.Context, argArguments []string, destination *T) error
- func NoOpHook(ctx context.Context, args []string) error
- func NoOpValidator() validatorAny
- type CLI
- func (c *CLI) Run(ctx context.Context, args []string) error
- func (cli *CLI) WithCommand(command *Command) *CLI
- func (cli *CLI) WithDescription(description string) *CLI
- func (cli *CLI) WithLongDescription(longDescription string) *CLI
- func (cli *CLI) WithPostRun(hook CommandHook) *CLI
- func (cli *CLI) WithPreRun(hook CommandHook) *CLI
- type ClingContextKey
- type CmdArg
- type CmdFlag
- type CmdInput
- type CmdInputWithDefaultAndValidator
- func NewBoolCmdInput(name string) CmdInputWithDefaultAndValidator[bool]
- func NewCmdSliceInput[T comparable](name string) CmdInputWithDefaultAndValidator[[]T]
- func NewIntCmdInput(name string) CmdInputWithDefaultAndValidator[int]
- func NewStringCmdInput(name string) CmdInputWithDefaultAndValidator[string]
- type Command
- func (command *Command) WithArgument(arg CmdArg) *Command
- func (command *Command) WithChildCommand(cmd *Command) *Command
- func (c *Command) WithDescription(description string) *Command
- func (command *Command) WithFlag(flag CmdFlag) *Command
- func (c *Command) WithLongDescription(longDescription string) *Command
- func (c *Command) WithPersistentPostRun(hook CommandHook) *Command
- func (c *Command) WithPersistentPreRun(hook CommandHook) *Command
- func (c *Command) WithPostRun(hook CommandHook) *Command
- func (c *Command) WithPreRun(hook CommandHook) *Command
- type CommandHandler
- type CommandHook
- type Comparator
- type ExitCoder
- type Validator
- func ComposeValidator[T any](validators ...Validator[T]) Validator[T]
- func NewComparatorValidator[T any](comparator Comparator[T]) Validator[T]
- func NewEnumValidator[T comparable](allowedValues ...T) Validator[T]
- func NewIntRangeValidator(min, max int) Validator[int]
- func NewStringLengthValidator(min, max int) Validator[string]
- type ValidatorProvider
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCLIngConfig = errors.New("invalid CLIng configuration")
var ErrInvalidCommand = errors.New("invalid command")
var ErrStringLen = errors.New("string length is not in range")
var ErrValidatorFailed = errors.New("validation failed")
Functions ¶
func Exit ¶ added in v0.3.5
func Exit(err error)
ExitWithErrorCode - exits the program with a non-zero exit code if the given error is non-nil. If the given error is an `ExitCoder`, the exit code will be taken from the error, otherwise it will be 1.
Uses `os.Exit` to exit the program. This function should be used only after when all cleanups are done.
func ExitWithMessage ¶ added in v0.3.5
func ExitWithMessage(err error)
ExitWithErrorMessage exits the program with a non-zero exit code if the given error is non-nil. If the given error is an `ExitCoder`, the exit code will be taken from the error, otherwise it will be 1. The error message will be printed to stderr as "Error: <message>\n".
Uses `os.Exit` to exit the program. This function should be used only after when all cleanups are done.
func Hydrate ¶
Hydrate populates the destination struct based on command-line arguments and context.
func NoOpValidator ¶ added in v0.3.0
func NoOpValidator() validatorAny
NoOpValidator returns a no-op validator for any type
Types ¶
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
func (*CLI) WithCommand ¶ added in v0.3.0
WithCommand adds a command to the CLI
func (*CLI) WithDescription ¶
WithDescription sets the description of the CLI
func (*CLI) WithLongDescription ¶
WithLongDescription sets the long description of the CLI
func (*CLI) WithPostRun ¶ added in v0.3.3
func (cli *CLI) WithPostRun(hook CommandHook) *CLI
WithPostRun sets the post-run hook for the CLI
func (*CLI) WithPreRun ¶ added in v0.3.3
func (cli *CLI) WithPreRun(hook CommandHook) *CLI
WithPreRun sets the pre-run hook for the CLI
type ClingContextKey ¶ added in v0.2.0
type ClingContextKey string
const (
ContextKeyCommand ClingContextKey = "command"
)
type CmdFlag ¶ added in v0.2.0
type CmdFlag interface { CmdInput // FromEnv sets the environment sources of the command flag. // The environment sources are used to get the default value of the flag. // The default value is the first non-empty value found in the environment. // This will override the default value set by WithDefault. FromEnv([]string) CmdFlag // contains filtered or unexported methods }
type CmdInput ¶ added in v0.2.0
type CmdInput interface { // Name returns the name of the command input. Name() string // Required marks the command input as required. Required() CmdInput // WithDescription sets the description of the command input. WithDescription(description string) CmdInput // Description returns the description of the command input. Description() string // AsFlag returns the command input as a flag. AsFlag() CmdFlag // AsArgument returns the command input as an argument. AsArgument() CmdArg // contains filtered or unexported methods }
type CmdInputWithDefaultAndValidator ¶ added in v0.2.0
type CmdInputWithDefaultAndValidator[S any] interface { CmdInput ValidatorProvider // WithDefault sets the default value of the command input. WithDefault(value S) CmdInputWithDefaultAndValidator[S] // WithValidator sets the validator of the command input. WithValidator(validator Validator[S]) CmdInputWithDefaultAndValidator[S] }
func NewBoolCmdInput ¶ added in v0.3.4
func NewBoolCmdInput(name string) CmdInputWithDefaultAndValidator[bool]
NewBoolCmdInput creates a new boolean command input with the given name.
func NewCmdSliceInput ¶ added in v0.3.0
func NewCmdSliceInput[T comparable](name string) CmdInputWithDefaultAndValidator[[]T]
func NewIntCmdInput ¶ added in v0.2.0
func NewIntCmdInput(name string) CmdInputWithDefaultAndValidator[int]
NewIntCmdInput creates a new integer command input with the given name.
func NewStringCmdInput ¶ added in v0.2.0
func NewStringCmdInput(name string) CmdInputWithDefaultAndValidator[string]
NewStringCmdInput creates a new string command input with the given name.
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
func NewCommand ¶
func NewCommand(name string, action CommandHandler) *Command
func (*Command) WithArgument ¶ added in v0.2.0
func (*Command) WithChildCommand ¶ added in v0.2.0
func (*Command) WithDescription ¶
func (*Command) WithLongDescription ¶
func (*Command) WithPersistentPostRun ¶ added in v0.3.0
func (c *Command) WithPersistentPostRun(hook CommandHook) *Command
func (*Command) WithPersistentPreRun ¶ added in v0.3.0
func (c *Command) WithPersistentPreRun(hook CommandHook) *Command
func (*Command) WithPostRun ¶ added in v0.3.0
func (c *Command) WithPostRun(hook CommandHook) *Command
func (*Command) WithPreRun ¶ added in v0.3.0
func (c *Command) WithPreRun(hook CommandHook) *Command
type Comparator ¶ added in v0.3.0
type ExitCoder ¶ added in v0.3.5
type ExitCoder interface {
ExitCode() int
}
func NewExitCoder ¶ added in v0.3.5
type Validator ¶ added in v0.2.0
Validator interface with non-generic Validate method
func ComposeValidator ¶ added in v0.3.0
ComposeValidator composes multiple validators for a specific type
func NewComparatorValidator ¶ added in v0.3.0
func NewComparatorValidator[T any](comparator Comparator[T]) Validator[T]
NewComparatorValidator creates a new validator that checks if the value satisfies the comparator.
func NewEnumValidator ¶ added in v0.2.0
func NewEnumValidator[T comparable](allowedValues ...T) Validator[T]
NewEnumValidator creates a new validator that checks if the value is one of the allowed values.
func NewIntRangeValidator ¶ added in v0.2.0
func NewStringLengthValidator ¶ added in v0.2.0
type ValidatorProvider ¶ added in v0.3.0
type ValidatorProvider interface {
// contains filtered or unexported methods
}