Utilities for making life with pflag easier
Example:
package main
import (
flag "github.com/ogier/pflag"
"github.com/alecthomas/flagutil"
)
var (
debugFlag = flag.Bool("debug", false, "enable debug mode")
logLevelFlag = flag.Int("log_level", 0, "set the log level for stdout logging")
)
func main() {
flag.Usage = flagutil.MakeUsage("usage: test <flags>\n\nA test application.", "")
flag.Parse()
}
Then calling --help
results in the following:
$ test --help
usage: test <flags>
A test application.
--debug=false enable debug mode
--log_level=0 set the log level for stdout logging
import "github.com/alecthomas/flagutil"
func MakeUsage(prefix, postfix string) func()
MakeUsage creates a function that generates nicely formatted usage text, usable as "flag.Usage".
func ParseFlagsFromJSON(r io.Reader, flags *flag.FlagSet) error
ParseFlagsFromJSON parses values from a JSON stream into a FlagSet. Keys in the JSON file that do not correspond to flags will result in an error.
func ParseFlagsFromMap(data map[string]interface{}, flags *flag.FlagSet) error
ParseFlagsFromMap loads flag values from a map[string]interface{} into a FlagSet. Keys in the JSON file that do not correspond to flags will result in an error.
func PrettyFormatFlags(w io.Writer, flags *flag.FlagSet)
PrettyFormatFlags formats standard Go flag FlagSets in a way that doesn't make your eyes bleed.