ethan zhou f1a9dfa966 QOL: build-info version fallback, UTF-8 length checks, inline ignore
Tier 1 (QOL), content batch:

- version: `--version` now works (rootCmd.Version is set), and `go install
  ...@latest` reports the embedded module version instead of "dev" via a
  runtime/debug.ReadBuildInfo() fallback. ldflags-injected release builds still
  take precedence.
- checks: App Store metadata length checks (name, description, keywords,
  promotional text) count characters with utf8.RuneCountInString, not bytes, so
  non-ASCII metadata is not falsely flagged as over Apple's limits.
- codescan: honor an inline `// greenlight:ignore[ rule-id]` directive on the
  matching line or the line directly above it (bare = all rules on the line).
- Tests for each.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 13:12:54 -07:00

35 lines
786 B
Go

package cli
import (
"fmt"
"runtime/debug"
"github.com/spf13/cobra"
)
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the greenlight version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("greenlight %s\n", resolveVersion())
},
}
// resolveVersion prefers the ldflags-injected version (release builds), then
// falls back to the module version embedded by the Go toolchain so that
// `go install ...@latest` / `@v1.2.3` reports a real version instead of "dev".
func resolveVersion() string {
if appVersion != "" && appVersion != "dev" {
return appVersion
}
if info, ok := debug.ReadBuildInfo(); ok {
if v := info.Main.Version; v != "" && v != "(devel)" {
return v
}
}
if appVersion != "" {
return appVersion
}
return "dev"
}