parent
3ad06351ae
commit
aa46ffffe4
|
@ -4,6 +4,10 @@ package main
|
|||
This simply parses the command line arguments using the default golang
|
||||
package called 'flag'. This can be used as a simple template to parse
|
||||
command line arguments in other programs.
|
||||
|
||||
It puts everything in the 'config' package which I think is a good
|
||||
wrapper around the 'flags' package and doesn't need a whole mess of
|
||||
global variables
|
||||
*/
|
||||
|
||||
import "log"
|
||||
|
@ -27,11 +31,9 @@ var customUsage = func() {
|
|||
func parseFlags() {
|
||||
var version string
|
||||
var race bool
|
||||
// var debug = os.Getenv("BUILDDEBUG") != ""
|
||||
var filename string
|
||||
var width int
|
||||
var height int
|
||||
// var timeout = "120s"
|
||||
var glDrift float64
|
||||
|
||||
flag.StringVar (&version, "version", "v0.1", "Set compiled in version string")
|
||||
|
@ -45,15 +47,14 @@ func parseFlags() {
|
|||
|
||||
// Set the output if something fails to stdout rather than stderr
|
||||
flag.CommandLine.SetOutput(os.Stdout)
|
||||
// flag.SetOutput(os.Stdout)
|
||||
|
||||
flag.Usage = customUsage
|
||||
flag.Parse()
|
||||
|
||||
if flag.Parsed() {
|
||||
log.Println("Parsed() worked")
|
||||
log.Println("flag.Parse() worked")
|
||||
} else {
|
||||
log.Println("Parsed() failed")
|
||||
log.Println("flag.Parse() failed")
|
||||
}
|
||||
|
||||
// keys := []string{"filename", "width", "height", "drift"}
|
||||
|
@ -64,15 +65,15 @@ func parseFlags() {
|
|||
|
||||
config.Set("width", width)
|
||||
config.Set("height", height)
|
||||
config.Set("uDrift", glDrift)
|
||||
config.Set("filename", filename)
|
||||
|
||||
// uDrift = float32(tmp)
|
||||
}
|
||||
|
||||
func parseConfig() {
|
||||
config.WithOptions(config.ParseEnv)
|
||||
parseFlags()
|
||||
|
||||
// config.LoadOSEnv([]string{"MAIL"})
|
||||
// config.LoadOSEnv([]string{"USER"})
|
||||
config.LoadOSEnv([]string{"MAIL"})
|
||||
config.LoadOSEnv([]string{"USER"})
|
||||
config.LoadOSEnv([]string{"BUILDDEBUG"})
|
||||
}
|
||||
|
|
|
@ -10,11 +10,12 @@ import (
|
|||
"golang.org/x/image/colornames"
|
||||
)
|
||||
|
||||
import "fmt"
|
||||
import "log"
|
||||
import "github.com/gookit/config"
|
||||
|
||||
func run() {
|
||||
// Set up window configs
|
||||
log.Println("width = ", config.Int("width"), "height = ", config.String("height"))
|
||||
cfg := pixelgl.WindowConfig{ // Default: 1024 x 768
|
||||
Title: "Golang GLSL",
|
||||
Bounds: pixel.R(0, 0, config.Float("width"), config.Float("height")),
|
||||
|
@ -79,17 +80,5 @@ func main() {
|
|||
// This parses the command line arguments
|
||||
parseConfig()
|
||||
|
||||
name := config.String("name")
|
||||
fmt.Println("name = ", name)
|
||||
|
||||
fmt.Println("name2 = ", config.String("name2"))
|
||||
fmt.Println("width = ", config.Int("width"))
|
||||
fmt.Println("height = ", config.String("height"))
|
||||
fmt.Println("drift = ", config.Int("drift"))
|
||||
fmt.Println("filename = ", config.String("filename"))
|
||||
fmt.Println("MAIL=", config.String("MAIL"))
|
||||
fmt.Println("mail=", config.String("mail"))
|
||||
fmt.Println("USER=", config.String("USER"))
|
||||
|
||||
pixelgl.Run(run)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue