From c047a2929f6407fc40cedb5517a059515230a755 Mon Sep 17 00:00:00 2001 From: Shekhar Vaidya Date: Sun, 21 Jun 2026 21:03:20 +0530 Subject: [PATCH] feat(cli): Version var injected via ldflags, updated --help text --- .github/workflows/cli-release.yml | 10 ++++++---- cli/main.go | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cli-release.yml b/.github/workflows/cli-release.yml index 022f292..c033772 100644 --- a/.github/workflows/cli-release.yml +++ b/.github/workflows/cli-release.yml @@ -20,11 +20,13 @@ jobs: - name: Build binaries working-directory: cli run: | + VERSION="${{ github.ref_name }}" + VERSION="${VERSION#cli/v}" mkdir -p ../dist - GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ../dist/msdl-linux-amd64 . - GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o ../dist/msdl-darwin-amd64 . - GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o ../dist/msdl-darwin-arm64 . - GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o ../dist/msdl-windows-amd64.exe . + GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.Version=${VERSION}" -o ../dist/msdl-linux-amd64 . + GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.Version=${VERSION}" -o ../dist/msdl-darwin-amd64 . + GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X main.Version=${VERSION}" -o ../dist/msdl-darwin-arm64 . + GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X main.Version=${VERSION}" -o ../dist/msdl-windows-amd64.exe . - name: Create GitHub Release uses: softprops/action-gh-release@v2 diff --git a/cli/main.go b/cli/main.go index 5a07250..3596774 100644 --- a/cli/main.go +++ b/cli/main.go @@ -13,6 +13,10 @@ import ( "time" ) +// Version is injected at build time via -ldflags "-X main.Version=0.3.0". +// Falls back to "dev" for local builds. +var Version = "dev" + // contributeURL is the MSDL backend endpoint that warms the shared link cache. // Override with MSDL_API_URL env var, e.g. export MSDL_API_URL=http://localhost:3002 const contributeSecret = "msdl-contribute-2026" @@ -78,6 +82,13 @@ Usage: Flags:`) fs.PrintDefaults() + fmt.Fprintln(os.Stderr, ` +Environment: + MSDL_NO_TELEMETRY=1 Disable anonymous usage reporting and update checks + MSDL_NO_CONTRIBUTE=1 Disable cache contribution + MSDL_API_URL= Override backend URL (default: https://api.msdl.tech-latest.com) + +More info: https://msdl.tech-latest.com/cli`) } productID := fs.String("id", "", "consumer product ID (skips product picker)") @@ -87,6 +98,9 @@ Flags:`) noContributeFlag := fs.Bool("no-contribute", false, "skip sharing the link with the msdl.tech cache") if err := fs.Parse(args); err != nil { + if err == flag.ErrHelp { + return nil // fs.Usage already printed + } return err } query := strings.Join(fs.Args(), " ")