Documentation ¶
Overview ¶
Package clap is a library for parsing command line flags in config struct using struct tags.
Example (Basic) ¶
package main import ( "fmt" "os" "go.ectobit.com/clap" ) func main() { type config struct { Host string Port int DB struct { Kind string Postgres struct { Host string } Mongo struct { Host clap.StringSlice } } } cfg := &config{} cmd := clap.New("cool", os.Args[1:]) cmd.MustConfig(cfg) fmt.Printf("Config:\n%#v\n", cfg) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clap ¶
type Clap struct {
// contains filtered or unexported fields
}
Clap is an abstraction of a CLI command.
func (*Clap) MustConfig ¶
func (c *Clap) MustConfig(config interface{})
MustConfig parses command line flags in supplied config struct using struct tags to optionally override generated environment variables' names, flags names, descriptions and default values.
func (*Clap) SetExit ¶ added in v0.2.1
SetExit overrides default exit function which uses os.Exit. Useful for testing.
type IntSlice ¶
type IntSlice []int
IntSlice implements flag.Getter interface for []int type.
func (*IntSlice) Set ¶
Set sets flag's value by splitting provided comma separated string.
type StringSlice ¶
type StringSlice []string
StringSlice implements flag.Getter interface for []string type.
func (*StringSlice) Set ¶
func (f *StringSlice) Set(s string) error
Set sets flag's value by splitting provided comma separated string.
type URL ¶
URL implements flag.Getter interface for url.URL type.