Golang Flag Helper
Simple helper to store your flags in a struct and allow environment overrides
environment
and shortname
are optional arguments. name
, default
, and usage
are required.
Usage Example
package main
import (
"fmt"
"git.home.127001.link/kormoc/flag"
)
var flags = struct {
StringExample string `name:"string" shortname:"s" environment:"TEST_STRING" default:"Hello World" usage:"String Test"`
IntExample int `name:"int" shortname:"i" environment:"TEST_INT" default:"8" usage:"Int Test"`
BoolExample bool `name:"bool" shortname:"b" environment:"TEST_BOOL" default:"true" usage:"Bool Test"`
}{}
func main() {
if err := flag.Parse(&flags); err != nil {
log.Fatal(err)
os.Exit(1)
}
fmt.Printf("%+v\n", flags)
}