Documentation
¶
Index ¶
- Constants
- Variables
- func LastErrorFromContext(ctx context.Context) error
- func NewCommand(name string, cmd interface{})
- func Parse(args []string) error
- func ParseCommand(cmd interface{}) error
- func ParseCommandAndRun(ctx context.Context, cmd interface{}) error
- func RegisterEnum(enumMap interface{})
- func RegisterNamedCompleter(name string, comp Completer)
- func Run(ctx context.Context) error
- type CLI
- func (cli *CLI) NewCommand(name string, cmd interface{})
- func (cli *CLI) Parse(args []string) (err error)
- func (cli *CLI) ParseCommand(cmd interface{}) error
- func (cli *CLI) ParseCommandAndRun(ctx context.Context, cmd interface{}) error
- func (cli *CLI) RegisterEnum(enumMap interface{})
- func (cli *CLI) Run(ctx context.Context) error
- type Case
- type Completer
- type Descriptioner
- type ErrCommandNotFound
- type ErrNoSuchFlag
- type FuncCompleter
- type Helper
- type OnErrorStrategy
- type Option
- func WithArgCase(c Case) Option
- func WithArgSplicer(s Splicer) Option
- func WithCmdCase(c Case) Option
- func WithCmdColumnSize(s uint) Option
- func WithEnvCase(c Case) Option
- func WithEnvSplicer(s Splicer) Option
- func WithFlagColumnSize(s uint) Option
- func WithGlobalArgsEnabled() Option
- func WithHelpFlags(long, short string) Option
- func WithIdentSize(s uint) Option
- func WithOnErrorStrategy(str OnErrorStrategy) Option
- func WithSeparator(sep Separator) Option
- func WithStructTags(tags StructTags) Option
- func WithVersionFlags(long, short string) Option
- type PersistentPostRunner
- type PersistentPreRunner
- type PostRunner
- type PreRunner
- type Runner
- type Separator
- type Splicer
- type StateFunc
- type StructTags
- type Versioner
Constants ¶
const ( // SplicerNone no splicer SplicerNone = iota // SplicerDot . splicer SplicerDot // SplicerDash - splicer SplicerDash // SplicerUnderscore _ splicer SplicerUnderscore )
Variables ¶
var ErrInvalidFlag = func(flg string) error { return fmt.Errorf("invalid flag: %s", flg) }
var ErrInvalidValue = func(val, flg string) error { return fmt.Errorf("invalid value: %s for flag: %s", val, flg) }
Functions ¶
func LastErrorFromContext ¶
LastErrorFromContext get the last error in case the execution continues on errors
func NewCommand ¶
func NewCommand(name string, cmd interface{})
NewCommand add new root command to defaultCLI
func ParseCommand ¶
func ParseCommand(cmd interface{}) error
ParseCommand creates a new root command from 1st OS arg and cmd and parses os.Args as input on default CLI
func ParseCommandAndRun ¶
ParseCommandAndRun combines ParseCommand & Run
func RegisterEnum ¶
func RegisterEnum(enumMap interface{})
RegisterEnum resgister an enum map to the default CLI
func RegisterNamedCompleter ¶
RegisterNamedCompleter adds named completers to be accessed by struct tag `complete:""`
Types ¶
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
CLI holds the cli state and configration
func (*CLI) NewCommand ¶
NewCommand add new root command to this CLI
func (*CLI) ParseCommand ¶
ParseCommand creates a new root command from 1st OS arg and cmd and parses os.Args as input
func (*CLI) ParseCommandAndRun ¶
ParseCommandAndRun combines ParseCommand & Run
func (*CLI) RegisterEnum ¶
func (cli *CLI) RegisterEnum(enumMap interface{})
RegisterEnum resgister an enum map. map must have string key and int/uint value. The value must also be a custom type e.g. type MyEnum uint32
type Case ¶
type Case uint32
Case string case
const ( // CaseNone string as is CaseNone Case = iota // CaseLower caselower CaseLower // CaseUpper CASEUPPER CaseUpper // CaseCamel CaseCamel CaseCamel // CaseCamelLower caseCamelLower CaseCamelLower // CaseSnake case_snake CaseSnake // CaseSnakeUpper CASE_SNAKE_UPPER CaseSnakeUpper // CaseKebab case-kebab CaseKebab // CaseKebabUpper CASE-KEBAB-UPPER CaseKebabUpper )
type Completer ¶
type Completer interface { // Complete returns suggestions filtered by val Complete(val string) []string }
Completer interface
type Descriptioner ¶
type Descriptioner interface {
Description() string
}
type ErrCommandNotFound ¶
type ErrCommandNotFound struct {
Command string
}
func (ErrCommandNotFound) Error ¶
func (e ErrCommandNotFound) Error() string
type ErrNoSuchFlag ¶
type ErrNoSuchFlag struct {
Flag string
}
func (ErrNoSuchFlag) Error ¶
func (e ErrNoSuchFlag) Error() string
type FuncCompleter ¶
type FuncCompleter struct {
// contains filtered or unexported fields
}
FuncCompleter creates a Completer from a func of the same signature
func NewFuncCmpleter ¶
func NewFuncCmpleter(f func(val string) []string) *FuncCompleter
NewFuncCmpleter instantiates a new FuncCompleter from f
func (*FuncCompleter) Complete ¶
func (fc *FuncCompleter) Complete(val string) []string
type OnErrorStrategy ¶
type OnErrorStrategy uint
OnErrorStrategy defines how errors are handled on execution
const ( // OnErrorBreak halt execution and return the error immediately OnErrorBreak OnErrorStrategy = iota // OnErrorPostRunners execute post runners in stack but break if post runner returns error. // LastErrorFromContext can be used to retrieve the error OnErrorPostRunners // OnErrorPostRunnersContinue execute post runners in stack ignoring errors. LastErrorFromContext // can be used to retrieve any error OnErrorPostRunnersContinue // OnErrorContinue ignore errors. LastErrorFromContext can be used to retrieve any error. OnErrorContinue )
type Option ¶
type Option func(o *cliOptions)
Option option type for Parser
func WithArgCase ¶
WithArgCase set the arg case. default is CaseCamelLower
func WithCmdCase ¶
WithCmdCase set the cmd case. default is CaseLower
func WithCmdColumnSize ¶
WithCmdColumnSize sets the command description column size in help
func WithEnvCase ¶
WithEnvCase set the env case. default is CaseSnakeUpper
func WithFlagColumnSize ¶
WithFlagColumnSize sets the flag description column size in help
func WithGlobalArgsEnabled ¶
func WithGlobalArgsEnabled() Option
WithGlobalArgsEnabled enable global argumets
func WithHelpFlags ¶
WithHelpFlags sets the help flags. Default --help,-h
func WithIdentSize ¶
WithIdentSize sets the ident size for command, flags & arguments displayed in help
func WithOnErrorStrategy ¶
func WithOnErrorStrategy(str OnErrorStrategy) Option
WithOnErrorStrategy sets the execution strategy for handling errors
func WithSeparator ¶
WithSeparator sets the flag separator charachter for help and completion
func WithStructTags ¶
func WithStructTags(tags StructTags) Option
WithStructTags sets the struct tags to be used by this parser
func WithVersionFlags ¶
WithVersionFlags sets the version flags. Default --version
type PersistentPostRunner ¶
PersistentPostRunner interface
type PersistentPreRunner ¶
PersistentPreRunner interface
type PostRunner ¶
PostRunner interface