Documentation
¶
Index ¶
- Constants
- Variables
- func Default[T interface{}](v T) *T
- func IsHelp(err error) bool
- type BoolOption
- type Command
- func (cmd *Command) GetBoolOption(name string) (bool, error)
- func (cmd *Command) GetIntOption(name string) (int, error)
- func (cmd *Command) GetStringOption(name string) (string, error)
- func (cmd *Command) GetSubcommand(arg string) (subcmd *Command)
- func (cmd *Command) Parse(args []string) (remaining []string, err error)
- type IntOption
- type Option
- type StringOption
Constants ¶
View Source
const ( // UTIL_GO_CLI_TRACE is the environment variable name for trace log. UTIL_GO_CLI_TRACE = "UTIL_GO_CLI_TRACE" // UTIL_GO_CLI_DEBUG is the environment variable name for debug log. UTIL_GO_CLI_DEBUG = "UTIL_GO_CLI_DEBUG" )
View Source
const (
// HelpOptionName is the option name for help.
HelpOptionName = "help"
)
Variables ¶
View Source
var ( // Stdout is the writer to be used for standard output. Stdout io.Writer = os.Stdout // Stderr is the writer to be used for standard error. Stderr io.Writer = os.Stderr )
View Source
var ( // TraceLog is the logger to be used for trace log. TraceLog = newLogger(Stderr, UTIL_GO_CLI_TRACE, "TRACE: ") // DebugLog is the logger to be used for debug log. DebugLog = newLogger(Stderr, UTIL_GO_CLI_DEBUG, "DEBUG: ") )
View Source
var ( ErrHelp = errors.New("help requested") ErrMissingOptionValue = errors.New("missing option value") ErrNoOption = errors.New("no option") ErrUnknownOption = errors.New("unknown option") ErrInvalidOptionType = errors.New("invalid option type") ErrUnexpectedError = errors.New("unexpected error") ErrDuplicateOptionName = errors.New("duplicate option name") ErrDuplicateSubCommand = errors.New("duplicate sub command") ErrMultipleOptionsDefaultValue = errors.New("multiple options with the same name, only one option can have a default value") )
Functions ¶
Types ¶
type BoolOption ¶
type BoolOption struct {
// Name is the name of the option.
Name string
// Short is the short name of the option.
Short string
// Environment is the environment variable name of the option.
Environment string
// Default is the default value of the option.
Default *bool
// Description is the description of the option.
Description string
// contains filtered or unexported fields
}
BoolOption is the option for bool value.
func (*BoolOption) GetDescription ¶
func (o *BoolOption) GetDescription() string
func (*BoolOption) GetEnvironment ¶
func (o *BoolOption) GetEnvironment() string
func (*BoolOption) GetName ¶
func (o *BoolOption) GetName() string
func (*BoolOption) GetShort ¶
func (o *BoolOption) GetShort() string
func (*BoolOption) HasDefault ¶
func (o *BoolOption) HasDefault() bool
type Command ¶
type Command struct {
// Name is the name of the command.
Name string
// Description is the description of the command.
Description string
// SubCommands is the subcommands of the command.
SubCommands []*Command
// Options is the options of the command.
Options []Option
// Usage is the usage of the command.
Usage func(c *Command)
// contains filtered or unexported fields
}
func (*Command) GetSubcommand ¶
type IntOption ¶
type IntOption struct {
// Name is the name of the option.
Name string
// Short is the short name of the option.
Short string
// Environment is the environment variable name of the option.
Environment string
// Default is the default value of the option.
Default *int
// Description is the description of the option.
Description string
// contains filtered or unexported fields
}
IntOption is the option for int value.
func (*IntOption) GetDescription ¶
func (*IntOption) GetEnvironment ¶
func (*IntOption) HasDefault ¶
type Option ¶
type Option interface {
// GetName returns the name of the option.
GetName() string
// GetShort returns the short name of the option.
GetShort() string
// GetEnvironment returns the environment variable name of the option.
GetEnvironment() string
// HasDefault returns whether the option has a default value.
HasDefault() bool
// GetDescription returns the description of the option.
GetDescription() string
// contains filtered or unexported methods
}
Option is the interface for the option.
type StringOption ¶
type StringOption struct {
// Name is the name of the option.
Name string
// Short is the short name of the option.
Short string
// Environment is the environment variable name of the option.
Environment string
// Default is the default value of the option.
Default *string
// Description is the description of the option.
Description string
// contains filtered or unexported fields
}
StringOption is the option for string value.
func (*StringOption) GetDescription ¶
func (o *StringOption) GetDescription() string
func (*StringOption) GetEnvironment ¶
func (o *StringOption) GetEnvironment() string
func (*StringOption) GetName ¶
func (o *StringOption) GetName() string
func (*StringOption) GetShort ¶
func (o *StringOption) GetShort() string
func (*StringOption) HasDefault ¶
func (o *StringOption) HasDefault() bool
Click to show internal directories.
Click to hide internal directories.