From 3fcfd4df05e64fde0a8beb4ade81b316311a7053 Mon Sep 17 00:00:00 2001 From: Robert Lowry Date: Thu, 5 Dec 2024 21:25:42 -0600 Subject: [PATCH] add -version flag and disply in help output (#91) --- .gitignore | 3 +++ cmd/gmars/main.go | 18 ++++++++++++++++++ cmd/vmars/main.go | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/.gitignore b/.gitignore index 4859eab..1db5539 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ /vmars /gmars /compile_test +/vmars.exe +/gmars.exe +/compile_test.exe \ No newline at end of file diff --git a/cmd/gmars/main.go b/cmd/gmars/main.go index 703a45a..6302851 100644 --- a/cmd/gmars/main.go +++ b/cmd/gmars/main.go @@ -9,7 +9,19 @@ import ( "github.com/bobertlo/gmars" ) +const ( + usage = `gMARS %s + +Usage: gmars [options] [warrior1.red] [warrior2.red] +` +) + func main() { + flag.Usage = func() { + fmt.Fprintf(flag.CommandLine.Output(), usage, "v0.1.14") + flag.PrintDefaults() + } + use88Flag := flag.Bool("8", false, "Enforce ICWS'88 rules") sizeFlag := flag.Int("s", 8000, "Size of core") procFlag := flag.Int("p", 8000, "Max. Processes") @@ -20,8 +32,14 @@ func main() { debugFlag := flag.Bool("debug", false, "Dump verbose reporting of simulator state") assembleFlag := flag.Bool("A", false, "Assemble and output warriors only") presetFlag := flag.String("preset", "", "Load named preset config (and ignore other flags)") + versionFlag := flag.Bool("version", false, "Print version and exit") flag.Parse() + if *versionFlag { + fmt.Printf("gMARS %s\n", "v0.1.14") + os.Exit(0) + } + var config gmars.SimulatorConfig if *presetFlag != "" { presetConfig, err := gmars.PresetConfig(*presetFlag) diff --git a/cmd/vmars/main.go b/cmd/vmars/main.go index a351256..9982c24 100644 --- a/cmd/vmars/main.go +++ b/cmd/vmars/main.go @@ -26,6 +26,13 @@ const ( defaultSpeedStep = 6 ) +const ( + usage = `vMARS %s + +Usage: vmars [options] [warrior1.red] [warrior2.red] +` +) + var ( mplusFaceSource *text.GoTextFaceSource @@ -53,6 +60,13 @@ func init() { } func main() { + + flag.Usage = func() { + // fmt. + fmt.Fprintf(flag.CommandLine.Output(), usage, "v0.1.14") + flag.PrintDefaults() + } + use88Flag := flag.Bool("8", false, "Enforce ICWS'88 rules") sizeFlag := flag.Int("s", 8000, "Size of core") procFlag := flag.Int("p", 8000, "Max. Processes") @@ -63,8 +77,14 @@ func main() { showReadFlag := flag.Bool("showread", false, "display reads in the visualizer") debugFlag := flag.Bool("debug", false, "Dump verbose reporting of simulator state") presetFlag := flag.String("preset", "", "Load named preset config (and ignore other flags)") + versionFlag := flag.Bool("version", false, "Print version and exit") flag.Parse() + if *versionFlag { + fmt.Printf("vMARS %s\n", "v0.1.14") + os.Exit(0) + } + var config gmars.SimulatorConfig if *presetFlag != "" { presetConfig, err := gmars.PresetConfig(*presetFlag)