From ad367a5aec351779a35ba91f5af315ccaff153c0 Mon Sep 17 00:00:00 2001 From: "Alexander \"NR4\" Kraus" Date: Sat, 12 Sep 2026 19:38:50 +0200 Subject: [PATCH] =?UTF-8?q?feat(=E2=80=8Ecmd/sointu-compile):=20validate?= =?UTF-8?q?=20-arch=20and=20-os=20command=20line=20params=20against=20poss?= =?UTF-8?q?ible=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #243 --- cmd/sointu-compile/main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/sointu-compile/main.go b/cmd/sointu-compile/main.go index 21c69c1..5797a87 100644 --- a/cmd/sointu-compile/main.go +++ b/cmd/sointu-compile/main.go @@ -43,10 +43,19 @@ func main() { extensionsOut := flag.String("e", "", "Output only the compiled files with these comma separated extensions. For example: h,asm") targetArch := flag.String("arch", runtime.GOARCH, "Target architecture. Defaults to OS architecture. Possible values: 386, amd64, wasm") output16bit := flag.Bool("i", false, "Compiled song should output 16-bit integers, instead of floats.") - targetOs := flag.String("os", runtime.GOOS, "Target OS. Defaults to current OS. Possible values: windows, darwin, linux. Anything else is assumed linuxy. Ignored when targeting wasm.") + targetOs := flag.String("os", runtime.GOOS, "Target OS. Defaults to current OS. Possible values: windows, darwin, linux. Anything else exits with error code. Ignored when targeting wasm.") versionFlag := flag.Bool("v", false, "Print version.") flag.Usage = printUsage flag.Parse() + // Validate and guard against some oddly specific typos: + if *targetOs != "windows" && *targetOs != "linux" && *targetOs != "darwin" { + fmt.Fprintf(os.Stderr, "error: invalid OS: `%s` (must be `windows`, `linux` or `darwin`).\n", *targetOs) + os.Exit(1) + } + if *targetArch != "386" && *targetArch != "amd64" && *targetArch != "wasm" { + fmt.Fprintf(os.Stderr, "error: invalid target architecture: `%s` (must be `386`, `amd64` or `wasm`).\n", *targetOs) + os.Exit(1) + } if *versionFlag { fmt.Println(version.VersionOrHash) os.Exit(0)