summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-02-19 07:16:10 -0600
committerJeff Carr <[email protected]>2024-02-19 07:16:10 -0600
commitf4605dbbd165348362ea38b6313b0818196cc675 (patch)
tree9ea94dd731a70809c84703930e07dc480fff8b7d /config.go
pulled out from my fork of upstream repo
Diffstat (limited to 'config.go')
-rw-r--r--config.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..da8313a
--- /dev/null
+++ b/config.go
@@ -0,0 +1,79 @@
+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"
+import "os"
+import "flag"
+import "fmt"
+import "github.com/gookit/config"
+
+var customUsage = func() {
+ fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
+ flag.PrintDefaults()
+
+ fmt.Println("")
+ fmt.Println("EXAMPLES:")
+ fmt.Println("")
+ fmt.Println(os.Args[0] + " --width 1024 --height 768 --drift .1 --filename shaders/seascape.glsl")
+ fmt.Println(os.Args[0] + " --width 640 --height 480 --filename shaders/planetfall.glsl")
+ fmt.Println("")
+}
+
+func parseFlags() {
+ var version string
+ var race bool
+ var filename string
+ var width int
+ var height int
+ var glDrift float64
+
+ flag.StringVar (&version, "version", "v0.1", "Set compiled in version string")
+
+ flag.StringVar (&filename, "filename", "shaders/seascape.glsl", "path to GLSL file")
+ flag.IntVar (&width, "width", 1024, "Width of the OpenGL Window")
+ flag.IntVar (&height, "height", 768, "Height of the OpenGL Window")
+
+ flag.Float64Var (&glDrift, "drift", 0.01, "Speed of the gradual camera drift")
+ flag.BoolVar (&race, "race", race, "Use race detector")
+
+ // Set the output if something fails to stdout rather than stderr
+ flag.CommandLine.SetOutput(os.Stdout)
+
+ flag.Usage = customUsage
+ flag.Parse()
+
+ if flag.Parsed() {
+ log.Println("flag.Parse() worked")
+ } else {
+ log.Println("flag.Parse() failed")
+ }
+
+ // keys := []string{"filename", "width", "height", "drift"}
+ // keys := []string{"width", "height", "drift"}
+
+// keys := []string{"height"}
+// config.LoadFlags(keys)
+
+ config.Set("width", width)
+ config.Set("height", height)
+ config.Set("glDrift", glDrift)
+ config.Set("filename", filename)
+}
+
+func parseConfig() {
+ config.WithOptions(config.ParseEnv)
+ parseFlags()
+
+ // config.LoadOSEnv([]string{"MAIL"})
+ // config.LoadOSEnv([]string{"USER"})
+ // config.LoadOSEnv([]string{"BUILDDEBUG"})
+}