Skip to content

Comments

fix: version not set correctly via ldflags#6

Open
Fuabioo wants to merge 2 commits intodmora:mainfrom
Fuabioo:fix/version-ldflags
Open

fix: version not set correctly via ldflags#6
Fuabioo wants to merge 2 commits intodmora:mainfrom
Fuabioo:fix/version-ldflags

Conversation

@Fuabioo
Copy link

@Fuabioo Fuabioo commented Jan 6, 2026

Summary

  • Fix version showing dev instead of actual tag when built via goreleaser
  • Add SetVersion() function to update both cli.Version and rootCmd.Version
  • Call SetVersion() from main() before Execute()

Problem

Running ch --version shows dev even when installed from goreleaser releases (e.g., via Homebrew tap).

Root Cause

The cobra command was initialized at package load time:

var rootCmd = &cobra.Command{
    Version: Version,  // Copies "dev" before main() runs
}

When main() later sets cli.Version = version, it's too late - rootCmd.Version already has "dev" baked in.

Solution

Added a SetVersion() function that updates both the exported Version variable AND the rootCmd.Version field.

Test Plan

  • Verified with manual ldflags: go build -ldflags="-X main.version=1.2.3" -o ch ./cmd/ch && ./ch --version shows ch version 1.2.3
  • Verified with full version info: shows ch version 1.2.3 (abc1234, 2026-01-06)
  • Unit tests pass
  • gofmt passes

🤖 Generated with Claude Code

The cobra command was initialized at package load time, copying the
default "dev" value before main() could update cli.Version via ldflags.

Added SetVersion() function that updates both cli.Version and
rootCmd.Version, and call it from main() before Execute().

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update golangci-lint to v2.0 for Go 1.25 compatibility
- Fix list command to exclude agents by default (was true, now false)
  This aligns with README documentation and E2E test expectations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants