version.go

 1package main
 2
 3import (
 4	"fmt"
 5
 6	"github.com/spf13/cobra"
 7)
 8
 9// version is set at build time via ldflags (-X main.version=...).
10// Defaults to "dev" for local go builds.
11var version = "dev"
12
13// formatVersion returns the user-facing version string.
14func formatVersion() string {
15	return fmt.Sprintf("bug version %s", version)
16}
17
18func runVersion(cmd *cobra.Command) error {
19	cmd.Println(formatVersion())
20	return nil
21}
22
23var versionCmd = &cobra.Command{
24	Use:   "version",
25	Short: "Print the bug CLI version",
26	Long: `Print the version of the bug CLI.
27
28The version is embedded at build time from the version field in flake.nix.
29This helps agents know which features are available in the installed binary.
30
31Example:
32  bug version`,
33	RunE: func(cmd *cobra.Command, args []string) error {
34		return runVersion(cmd)
35	},
36}