flag - command line flags.
A flag is declared before parsing and read after it, from the Value of what the declaration returned:
flag = import("flag")port = flag.Int("port", 8080, "the port to listen on")
quiet = flag.Bool("q", false, "say nothing")
rest = flag.Parse()if failed(rest) { println(rest); exit(2) }
println("port {port.Value}, files {rest}")The forms understood are -name value, -name=value and, for a boolean, -name on its own. Two dashes work like one, and a bare -- ends the flags: what follows is returned as it is, dashes included. -h and --help print the usage and exit.
A program that parses something other than its own command line, a test for one, builds its own set with New and calls set.Parse(args).
¶New = fn(name)source
New returns an empty set of flags named after the program it parses for.
¶Name = namevaluesource
¶String = fn(name, value, usage)source
¶Int = fn(name, value, usage)source
¶Float = fn(name, value, usage)source
¶Bool = fn(name, value, usage)source
¶Usage = fn()source
Usage returns the lines describing the flags, the way the help prints them.
¶Lookup = fn(name)source
Lookup returns the flag named name, or null.
¶Parse = fn(args)source
Parse reads args, which are the arguments without the program name, and returns the ones left over after the flags. An unknown flag or a value of the wrong kind gives an error.
¶Reset = fn()source
Reset puts every flag back to the value it was declared with, which is what a test parsing twice with the same set needs.
¶CommandLine = New(if len(os.Args) > 0 { os.Args [0] } else { "program" })valuesource
The set behind the functions of the module, which parses the command line of the program itself.
¶Name = namevaluesource
¶String = fn(name, value, usage)source
¶Int = fn(name, value, usage)source
¶Float = fn(name, value, usage)source
¶Bool = fn(name, value, usage)source
¶Usage = fn()source
Usage returns the lines describing the flags, the way the help prints them.
¶Lookup = fn(name)source
Lookup returns the flag named name, or null.
¶Parse = fn(args)source
Parse reads args, which are the arguments without the program name, and returns the ones left over after the flags. An unknown flag or a value of the wrong kind gives an error.
¶Reset = fn()source
Reset puts every flag back to the value it was declared with, which is what a test parsing twice with the same set needs.
¶String = fn(name, value, usage)source
¶Int = fn(name, value, usage)source
¶Float = fn(name, value, usage)source
¶Bool = fn(name, value, usage)source
¶Lookup = fn(name)source
¶Usage = fn()source
¶Parse = fn()source
Parse reads the command line of the program, past its name, and returns the arguments that are not flags.