Documentation ¶
Overview ¶
Package gli is a CLI parsing and mapping library.
type globalCmd struct { Name string Age int } func (g *globalCmd) Run() error { // : } app := gli.NewWith(&globalCmd{}) err := app.Run(os.Args)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotDefined means "an option or a subcommand is not defined in the passed struct". ErrNotDefined = errors.New("not defined") // ErrNotRunnable means "Run method is not defined for the passed struct". ErrNotRunnable = fmt.Errorf("command not runnable") // ErrOptCanNotBeSet is a reflect related error. ErrOptCanNotBeSet = fmt.Errorf("option can not be set") )
Functions ¶
Types ¶
type App ¶
type App struct { // Name is the app name. default: the name of the executable file Name string // Desc is a description of the app // {{Name}} - {{Desc}} Desc string // Usage is a long(multiline) usage text Usage string // Version numbers Version string // Copyright the app author has Copyright string // CliTag is a tag key. default: `cli` CliTag string // HelpTag is a tag key. default: `help` HelpTag string // UsageTag is a tag key. default: `usage` UsageTag string // DefaultTag is a tag key. default: `default` DefaultTag string // DefDescTag is a tag key. default: `defdesc` DefDescTag string // EnvTag is a tag key. default: `env` EnvTag string // RequiredTag is a tag key. default: `required` RequiredTag string // MyCommandABC => false(default): "mycommandabc" , true: "my-command-abc" HyphenedCommandName bool // MyOptionABC => false(default): "myoptionabc" , true: "my-option-abc" HyphenedOptionName bool // OptionsGrouped(default: true) allows -abc may be treated as -a -b -c. OptionsGrouped bool DoubleHyphen bool // SuppressErrorOutput is an option to suppresses on cli parsing error. SuppressErrorOutput bool Stdout, Stderr *os.File // true(default): bool options have --no-xxx options. // AutoNoBoolOptions also appends --no-xxx descriptions in help doc if . // // Options: // opt1, o1 A bool option // opt2, o2 A bool option (default: true) // --no-opt2 // opt1, o1 A bool option AutoNoBoolOptions bool // contains filtered or unexported fields }
App contains parsing and parsed data.
func New ¶
func New() App
New makes main gli instance to parse and invoke hooks.
App bridges between application logic code and CLI definition (your struct).
Next, call Bind() to set the CLI up.
func (*App) AddExtraCommand ¶
AddExtraCommand adds a sub command.
type Date ¶
Date is a parsable type of date.
DEPLICATED: use time.Time instead. CAUTION: time.Time is Local timezone, gli.Date is UTC.
type Duration ¶
Duration is a parsable type of time duration.
DEPLICATED: use time.Duration instead.
type IntList ¶
type IntList []int
IntList is a parsable type of [1, 2, 3]
type MultipleOptionParser ¶
type MultipleOptionParser interface { // Parse parses string str and converts it to the receiver's type. // Bool nondefFirst is true if you shuld re-initialize. Parse(str string, nondefFirst bool) error }
MultipleOptionParser sets a converted value to itself. This is for options where the value is passed multiple times, such as in a list.
type OptionParser ¶
type OptionParser interface { // Parse parses string str and converts it to the receiver's type. Parse(str string) error }
OptionParser sets a converted value to itself.