Documentation ¶
Index ¶
- type Flag
- type Set
- func (s *Set) Arg(i int) string
- func (s *Set) Bool(name string, usage string) *bool
- func (s *Set) BoolVar(p *bool, name string, usage string)
- func (s *Set) Defaults() string
- func (s *Set) Int(name string, usage string) *int
- func (s *Set) IntVar(p *int, name string, usage string)
- func (s *Set) Parse(args ...string) (err error)
- func (s *Set) PrintError(e string)
- func (s *Set) PrintUsage()
- func (s *Set) Set(name string) bool
- func (s *Set) String(name string, usage string) *string
- func (s *Set) StringVar(p *string, name string, usage string)
- func (s *Set) Strings(name string, usage string) *[]string
- func (s *Set) StringsVar(p *[]string, name string, usage string)
- func (s *Set) Var(value Value, name string, usage string)
- func (s *Set) Visit(fn func(*Flag))
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶ added in v0.4.0
type Set struct { Args []string // contains filtered or unexported fields }
func (*Set) Bool ¶ added in v0.4.0
Example ¶
package main import ( "fmt" "os" "lesiw.io/flag" ) func main() { var ( flags = flag.NewSet(os.Stderr, "example") bool = flags.Bool("b", "some bool") ) if err := flags.Parse("example", "-b"); err != nil { panic(err) } fmt.Println("bool:", *bool) }
Output: bool: true
func (*Set) PrintError ¶ added in v0.4.0
func (*Set) PrintUsage ¶ added in v0.4.0
func (s *Set) PrintUsage()
func (*Set) String ¶ added in v0.4.0
Example ¶
package main import ( "fmt" "os" "lesiw.io/flag" ) func main() { var ( flags = flag.NewSet(os.Stderr, "example") word = flags.String("w", "a string") ) if err := flags.Parse("example", "-wfoo"); err != nil { panic(err) } fmt.Println("word:", *word) }
Output: word: foo
Example (Mixed) ¶
package main import ( "fmt" "os" "lesiw.io/flag" ) func main() { var ( flags = flag.NewSet(os.Stderr, "example") boola = flags.Bool("a", "some bool") boolb = flags.Bool("b", "some other bool") word = flags.String("c", "a string") ) if err := flags.Parse("example", "-abcde"); err != nil { panic(err) } fmt.Println("bool 'a':", *boola) fmt.Println("bool 'b':", *boolb) fmt.Println("word:", *word) }
Output: bool 'a': true bool 'b': true word: de
func (*Set) StringsVar ¶ added in v0.6.0
Click to show internal directories.
Click to hide internal directories.