From b0e3ff8d36546983b4d1e768866f91faeea82980 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Sun, 26 May 2024 12:33:16 +0200 Subject: [PATCH] print version from main --- config.go | 11 +++-------- main.go | 6 ++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/config.go b/config.go index 7bb08da..fc1989f 100644 --- a/config.go +++ b/config.go @@ -3,12 +3,12 @@ package main import ( "fmt" "log" - "os" "github.com/spf13/pflag" "github.com/tlinden/golsky/rle" ) +// all the settings comming from commandline, but maybe tweaked later from the UI type Config struct { Width, Height, Cellsize, Density int // measurements ScreenWidth, ScreenHeight int @@ -20,12 +20,12 @@ type Config struct { Statefile string // load game state from it if non-nil StateGrid *Grid // a grid from a statefile Wrap bool // wether wraparound mode is in place or not + ShowVersion bool } func ParseCommandline() *Config { config := Config{} - showversion := false var rule string var rlefile string @@ -41,7 +41,7 @@ func ParseCommandline() *Config { pflag.StringVarP(&rlefile, "rle-file", "f", "", "RLE pattern file") pflag.StringVarP(&config.Statefile, "load-state-file", "l", "", "game state file") - pflag.BoolVarP(&showversion, "version", "v", false, "show version") + pflag.BoolVarP(&config.ShowVersion, "version", "v", false, "show version") pflag.BoolVarP(&config.Paused, "paused", "p", false, "do not start simulation (use space to start)") pflag.BoolVarP(&config.Debug, "debug", "d", false, "show debug info") pflag.BoolVarP(&config.NoGrid, "nogrid", "n", false, "do not draw grid lines") @@ -52,11 +52,6 @@ func ParseCommandline() *Config { pflag.Parse() - if showversion { - fmt.Printf("This is golsky version %s\n", VERSION) - os.Exit(0) - } - // check if we have been given an RLE file to load config.RLE = GetRLE(rlefile) if config.RLE != nil { diff --git a/main.go b/main.go index 46b4204..f40d2cd 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "log" "os" @@ -36,6 +37,11 @@ func GetRLE(filename string) *rle.RLE { func main() { config := ParseCommandline() + if config.ShowVersion { + fmt.Printf("This is golsky version %s\n", VERSION) + os.Exit(0) + } + game := NewGame(config, Play) // setup environment