make a clean file that just is for parsing the command line
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
80982259a0
commit
466083852c
|
@ -0,0 +1 @@
|
|||
community/seascape-shader/seascape-shader
|
|
@ -0,0 +1,67 @@
|
|||
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.
|
||||
*/
|
||||
|
||||
import "log"
|
||||
import "os"
|
||||
import "flag"
|
||||
import "fmt"
|
||||
|
||||
var (
|
||||
version string
|
||||
race bool
|
||||
debug = os.Getenv("BUILDDEBUG") != ""
|
||||
filename string
|
||||
width int
|
||||
height int
|
||||
timeout = "120s"
|
||||
uDrift float32
|
||||
)
|
||||
|
||||
var customUsage = func() {
|
||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
|
||||
fmt.Println("")
|
||||
fmt.Println("EXAMPLE:")
|
||||
fmt.Println("")
|
||||
fmt.Println("seascape-shader --width 640 --height 480 --filename shaders/planetfall.glsl")
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
func parseFlags() {
|
||||
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")
|
||||
var tmp float64
|
||||
flag.Float64Var (&tmp, "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.SetOutput(os.Stdout)
|
||||
|
||||
flag.Usage = customUsage
|
||||
flag.Parse()
|
||||
|
||||
if flag.Parsed() {
|
||||
log.Println("Parsed() worked. width=",width)
|
||||
} else {
|
||||
log.Println("Parsed() failed. width=",width)
|
||||
}
|
||||
|
||||
// if err := flag.Parse(); err != nil {
|
||||
// log.Println("Example:",width)
|
||||
// }
|
||||
|
||||
|
||||
uDrift = float32(tmp)
|
||||
log.Println("width=",width)
|
||||
log.Println("height=",height)
|
||||
log.Println("uDrift=",uDrift)
|
||||
}
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"time"
|
||||
"log"
|
||||
|
||||
"github.com/go-gl/mathgl/mgl32"
|
||||
|
||||
|
@ -11,20 +10,6 @@ import (
|
|||
"golang.org/x/image/colornames"
|
||||
)
|
||||
|
||||
import "flag"
|
||||
import "os"
|
||||
|
||||
var (
|
||||
version string
|
||||
race bool
|
||||
debug = os.Getenv("BUILDDEBUG") != ""
|
||||
filename string
|
||||
width int
|
||||
height int
|
||||
timeout = "120s"
|
||||
uDrift float32
|
||||
)
|
||||
|
||||
func run() {
|
||||
// Set up window configs
|
||||
cfg := pixelgl.WindowConfig{ // Default: 1024 x 768
|
||||
|
@ -86,25 +71,6 @@ func run() {
|
|||
|
||||
}
|
||||
|
||||
func parseFlags() {
|
||||
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")
|
||||
var tmp float64
|
||||
flag.Float64Var (&tmp, "drift", 0.01, "Speed of the gradual camera drift")
|
||||
flag.BoolVar (&race, "race", race, "Use race detector")
|
||||
|
||||
// this parses the arguements
|
||||
flag.Parse()
|
||||
|
||||
uDrift = float32(tmp)
|
||||
log.Println("width=",width)
|
||||
log.Println("height=",height)
|
||||
log.Println("uDrift=",uDrift)
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
parseFlags()
|
||||
|
||||
|
|
Loading…
Reference in New Issue