Documentation
¶
Index ¶
- Variables
- func LoadConfigFile(dst interface{}, filename string) error
- func TerminalSize() (int, int, error)
- func TypeName(t reflect.Type) string
- func UnmarshalConfig(b []byte, dst interface{}) error
- type Append
- type Argp
- func (argp *Argp) AddArg(dst interface{}, name, description string)
- func (argp *Argp) AddCmd(cmd Cmd, name, description string) *Argp
- func (argp *Argp) AddOpt(dst interface{}, short, name string, description string)
- func (argp *Argp) AddRest(dst interface{}, name, description string)
- func (argp *Argp) IsSet(name string) bool
- func (argp *Argp) Parse()
- func (argp *Argp) PrintHelp()
- type Cmd
- type Config
- type Count
- type Custom
- type Dict
- type DictSource
- type DictSourceFunc
- type FileDict
- type FileList
- type InlineDict
- type InlineList
- type List
- type ListSource
- type ListSourceFunc
- type SQLDict
- type SQLList
- type StaticDict
- type Var
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ShowUsage error = fmt.Errorf("bad command usage")
ShowUsage can be returned from a command to show the help message.
Functions ¶
func LoadConfigFile ¶
LoadConfigFile loads .cf, .cfg, .toml, and .yaml files.
func TerminalSize ¶
func UnmarshalConfig ¶
UnmarshalConfig parses simple .cf or .cfg files.
Types ¶
type Append ¶
type Append struct {
I interface{}
}
Append is an option that appends to a slice, e.g. -a 5 -a 6 sets the value to [5 6]
type Argp ¶
type Argp struct { Cmd Description string Error *log.Logger // contains filtered or unexported fields }
Argp is a (sub) command parser
func New ¶
New returns a new command parser that can set options and returns the remaining arguments from `Argp.Parse`.
func NewCmd ¶
NewCmd returns a new command parser that invokes the Run method of the passed command structure. The `Argp.Parse()` function will not return and will call os.Exit() with 0, 1 or 2 as the argument.
type Count ¶
type Count struct {
I interface{}
}
Count is a counting option, e.g. -vvv sets count to 3, or -v=3 sets it directly
Example ¶
var count int argp := New("count variable") argp.AddOpt(Count{&count}, "c", "count", "") _, _, err := argp.parse([]string{"-ccc"}) if err != nil { panic(err) } fmt.Println(count)
Output: 3
type Custom ¶
type Custom interface { Help() (string, string) // value and type representations for help Scan(string, []string) (int, error) // scan values from command line }
Example ¶
custom := CustomVar{} argp := New("custom variable") argp.AddOpt(&custom, "", "custom", "") _, _, err := argp.parse([]string{"--custom", "1", "/", "2"}) if err != nil { panic(err) } fmt.Println(custom.Num, "/", custom.Div)
Output: 1 / 2
type Dict ¶
type Dict struct { DictSource Sources map[string]DictSourceFunc Values []string }
Dict is an option that loads key-value map from a source (such as mysql).
func (*Dict) AddSource ¶
func (dict *Dict) AddSource(typ string, f DictSourceFunc)
type DictSource ¶
func NewFileDict ¶
func NewFileDict(s []string) (DictSource, error)
func NewInlineDict ¶
func NewInlineDict(s []string) (DictSource, error)
func NewStaticDict ¶
func NewStaticDict(s []string) (DictSource, error)
type DictSourceFunc ¶
type DictSourceFunc func([]string) (DictSource, error)
type FileDict ¶
type FileDict struct {
InlineDict
}
type FileList ¶
type FileList struct {
InlineList
}
type InlineDict ¶
type InlineDict struct {
// contains filtered or unexported fields
}
func (*InlineDict) Close ¶
func (t *InlineDict) Close() error
type InlineList ¶
type InlineList struct {
// contains filtered or unexported fields
}
func (*InlineList) Close ¶
func (t *InlineList) Close() error
func (*InlineList) List ¶
func (t *InlineList) List() ([]string, error)
type List ¶
type List struct { ListSource Sources map[string]ListSourceFunc Values []string }
List is an option that loads a list of values from a source (such as mysql).
func (*List) AddSource ¶
func (list *List) AddSource(typ string, f ListSourceFunc)
type ListSource ¶
func NewFileList ¶
func NewFileList(s []string) (ListSource, error)
func NewInlineList ¶
func NewInlineList(s []string) (ListSource, error)
type ListSourceFunc ¶
type ListSourceFunc func([]string) (ListSource, error)
type StaticDict ¶
type StaticDict struct {
// contains filtered or unexported fields
}
func (*StaticDict) Close ¶
func (t *StaticDict) Close() error