Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"os"
"regexp"
"runtime"
"runtime/debug"
"strings"

Expand All @@ -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, "")
Expand Down Expand Up @@ -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 == "" {
Expand Down
34 changes: 34 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading