Documentation ¶
Overview ¶
Package largo implements command-line-like string/[]string parsing. Unlike standard `flag` package, largo allows to provide flag args in **unordered** way, such as:
dosomething -upper -count 3 say hello dosomething -upper say -count=3 hello dosomething say -upper hello -count 3
All should be parsed and resulted to the same args, such as:
Command: dosomething Rest args: [say, hello] Flags: upper: true count: 3
`largo` parses given string/[]string as follows:
dosomething say -count 3 hello -upper ----------- command ------- ------ flag flag ---- -------- rest rest
// TODO: Add more information here in near future ;)
Index ¶
- Variables
- func Tokenize(s string) (tokens []string)
- func TokenizeBytes(b []byte) (tokens []string)
- type ErrorHandling
- type Flag
- type FlagSet
- func (fset *FlagSet) BoolVar(dest *bool, name string, defaultval bool, usage string) *Flag
- func (fset *FlagSet) HelpMessage() string
- func (fset *FlagSet) HelpRequested() bool
- func (fset *FlagSet) IntVar(dest *int, name string, defaultval int, usage string) *Flag
- func (fset *FlagSet) List() []*Flag
- func (fset *FlagSet) Lookup(name string) *Flag
- func (fset *FlagSet) Parse(arguments []string) error
- func (fset *FlagSet) ParseLine(line string) error
- func (fset *FlagSet) PrintDefaultUsage(w io.Writer) error
- func (fset *FlagSet) Rest() []string
- func (fset *FlagSet) StringVar(dest *string, name string, defaultval string, usage string) *Flag
- func (fset *FlagSet) Var(value Value, name string, usage string) *Flag
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrHelp = errors.New("flag: help requested")
Functions ¶
func TokenizeBytes ¶
Types ¶
type ErrorHandling ¶
type ErrorHandling int
const ( ContinueOnError ErrorHandling = iota // Return a descriptive error. ExitOnError // Call os.Exit(2) or for -h/-help Exit(0). PanicOnError // Call panic with a descriptive error. )
type Flag ¶
type FlagSet ¶
type FlagSet struct { Name string // Usage ... // FIXME: Write something here Usage func() Output io.Writer Description string // contains filtered or unexported fields }
func NewFlagSet ¶
func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet
func (*FlagSet) HelpMessage ¶
func (*FlagSet) HelpRequested ¶
func (*FlagSet) Rest ¶
Example ¶
var upper bool var count int fset := NewFlagSet("say", ContinueOnError) fset.BoolVar(&upper, "upper", false, "Make chars uppercase").Alias("U") fset.IntVar(&count, "count", 1, "Count to say that word").Alias("c") // In most cases, it comes from `os.Args`. args := []string{"say", "-count", "3", "hello", "-upper", "hiromu"} fset.Parse(args) fmt.Printf("upper: %v\ncount: %v\nrest: %v\n", upper, count, fset.Rest())
Output: upper: true count: 3 rest: [hello hiromu]
Source Files ¶
Click to show internal directories.
Click to hide internal directories.