From a8cf410af0405c944a0565daf560c51d30e7be9c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 23 May 2026 22:00:25 +0000 Subject: [PATCH] feat: update --version to include Go version and os/arch Agent-Logs-Url: https://github.com/UnitVectorY-Labs/mcp-acronym-lookup/sessions/a0f57103-0312-45b6-b33f-eeab7ddeafd4 Co-authored-by: JaredHatfield <208119+JaredHatfield@users.noreply.github.com> --- main.go | 18 ++++++++++++++++++ main_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 main_test.go diff --git a/main.go b/main.go index 8c36472..fd25aa0 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "log" "os" "regexp" + "runtime" "runtime/debug" "strings" @@ -26,6 +27,16 @@ var nonAlpha = regexp.MustCompile("[^A-Za-z]+") var Version = "dev" // This will be set by the build systems to the release version +var semverRe = regexp.MustCompile(`^\d+\.\d+\.\d+`) + +func buildVersionOutput(version string) string { + normalized := version + if semverRe.MatchString(normalized) && !strings.HasPrefix(normalized, "v") { + normalized = "v" + normalized + } + return fmt.Sprintf("%s (%s, %s/%s)", normalized, runtime.Version(), runtime.GOOS, runtime.GOARCH) +} + // sanitizeKey removes non-alphabetic characters and lowercases the string func sanitizeKey(s string) string { s = nonAlpha.ReplaceAllString(s, "") @@ -80,8 +91,15 @@ func main() { // CLI flag for Streamable HTTP transport var httpAddr string flag.StringVar(&httpAddr, "http", "", "run in Streamable HTTP transport on the given address, e.g. :8080") + var showVersion bool + flag.BoolVar(&showVersion, "version", false, "print version and exit") flag.Parse() + if showVersion { + fmt.Printf("mcp-acronym-lookup version %s\n", buildVersionOutput(Version)) + os.Exit(0) + } + // Path to CSV file from environment csvPath := os.Getenv("ACRONYM_FILE") if csvPath == "" { diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..4175d92 --- /dev/null +++ b/main_test.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "runtime" + "testing" +) + +func TestBuildVersionOutputAddsVPrefixAndMetadata(t *testing.T) { + got := buildVersionOutput("1.2.3") + want := fmt.Sprintf("v1.2.3 (%s, %s/%s)", runtime.Version(), runtime.GOOS, runtime.GOARCH) + + if got != want { + t.Fatalf("unexpected version output: got %q, want %q", got, want) + } +} + +func TestBuildVersionOutputPreservesExistingVPrefix(t *testing.T) { + got := buildVersionOutput("v1.2.3") + want := fmt.Sprintf("v1.2.3 (%s, %s/%s)", runtime.Version(), runtime.GOOS, runtime.GOARCH) + + if got != want { + t.Fatalf("unexpected version output: got %q, want %q", got, want) + } +} + +func TestBuildVersionOutputNoVPrefixForDev(t *testing.T) { + got := buildVersionOutput("dev") + want := fmt.Sprintf("dev (%s, %s/%s)", runtime.Version(), runtime.GOOS, runtime.GOARCH) + + if got != want { + t.Fatalf("unexpected version output: got %q, want %q", got, want) + } +}