Documentation ¶
Overview ¶
Package flag9 provides Plan 9-like flag parsing.
Though it is not as convenient to use as the flag package from the standard library, it provides more control over what portion of the arguments is actually parsed.
See the example for a typical usage case.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Argc ¶
func Argc() rune
Argc returns the current option character from the command-line arguments.
func Argf ¶
Argf tries to return the current option argument (the rest of the option string if it's not empty, or the next argument) from the command-line arguments. If none is present, the empty string and false are returned. Otherwise, the option argument and true are returned.
It must not be called multiple times for the same argument.
func Argv ¶
func Argv() []string
Argv returns the command-line arguments that are not (yet) processed.
Types ¶
type Args ¶
type Args struct {
// contains filtered or unexported fields
}
Args are a set of arguments being parsed.
Example ¶
s := []string{"-ab", "-carg", "--", "-d"} args := NewArgs(s) for args.Next() { switch args.Argc() { case 'a', 'b': fmt.Printf("%c\n", args.Argc()) case 'c': argf, ok := args.Argf() if ok { fmt.Println("c", argf) } else { fmt.Println("c without argument") } case 'd': fmt.Println("not reached") } } fmt.Println(args.Argv())
Output: a b c arg [-d]
func NewArgs ¶
NewArgs returns an Args structure that can be used to parse the given slice of strings.
func (*Args) Argf ¶
Argf tries to return the current option argument (the rest of the option string if it's not empty, or the next member in the slice). If none is present, the empty string and false are returned. Otherwise, the option argument and true are returned.
It must not be called multiple times for the same argument.