// !!! !!!
// WARNING: Code automatically generated. Editing discouraged.
// !!! !!!

package {{.PackageName}}

import (
	"flag"
	"fmt"
	"os"
	
	"github.com/go-easygen/easygen"
)

////////////////////////////////////////////////////////////////////////////
// Constant and data type/structure definitions

//const progname = "{{.ProgramName}}" // os.Args[0]

////////////////////////////////////////////////////////////////////////////
// Global variables definitions

////////////////////////////////////////////////////////////////////////////
// Commandline definitions

func init() {

	// set default values for command line parameters{{range .Options}}{{if eq .Name "SEPARATOR" }}

{{else}}
	flag.{{clk2uc .Type}}Var(&easygen.{{$.StructVar}}.{{.Name}}, "{{.Flag}}", {{.Value}},
		"{{.Usage}}"){{end}}{{end}}

	// Now override those default values from environment variables{{range .Options}}{{if eq .Name "SEPARATOR" }}

{{else}}{{if eq .Type "string" }}{{$envVar := printf "%s_%s" (clk2ss $.ProgramName) (clk2ss .Flag)}}
	if len(easygen.{{$.StructVar}}.{{.Name}}) == 0 ||
		len(os.Getenv("{{$envVar}}")) != 0 {
		easygen.{{$.StructVar}}.{{.Name}} = os.Getenv("{{$envVar}}")
	}{{end}}{{end}}{{end}}

}

{{if eqf .UsageSummary "True" }}
const USAGE_SUMMARY = "{{range .Options}}{{if eq .Name "SEPARATOR" }}\n{{else}}{{$envVar := printf "%s_%s" (clk2ss $.ProgramName) (clk2ss .Flag)}}  -{{.Flag}}\t{{.Usage}} ({{$envVar}})\n{{end}}{{end}}\nDetails:\n\n"
{{end}}

// Usage function shows help on commandline usage
func Usage() {
	fmt.Fprintf(os.Stderr,
		"%s version %s\n{{.UsageLead}}",
		progname, version, progname){{if eq .UsageSummary "TRUE" }}
	fmt.Fprintf(os.Stderr, USAGE_SUMMARY){{end}}
	flag.PrintDefaults()
	fmt.Fprintf(os.Stderr,
		"{{.UsageEnd}}")
	os.Exit(0)
}

