1package commands
 2
 3import (
 4	"log/slog"
 5
 6	"github.com/spf13/cobra"
 7
 8	"github.com/git-bug/git-bug/commands/execenv"
 9)
10
11// TODO: 0.12.0: remove deprecated build vars
12var (
13	GitCommit   string
14	GitLastTag  string
15	GitExactTag string
16)
17
18func newVersionCommand(env *execenv.Env) *cobra.Command {
19	return &cobra.Command{
20		Use:     "version",
21		Short:   "Print version information",
22		Example: "git bug version",
23		Long: `
24Print version information.
25
26Format:
27  git-bug <version> [commit[/dirty]] <compiler version> <platform> <arch>
28
29Format Description:
30  <version> may be one of:
31  	- A semantic version string, prefixed with a "v", e.g. v1.2.3
32  	- "undefined" (if not provided, or built with an invalid version string)
33
34  [commit], if present, is the commit hash that was checked out during the
35  build. This may be suffixed with '/dirty' if there were local file
36  modifications. This is indicative of your build being patched, or modified in
37  some way from the commit.
38
39  <compiler version> is the version of the go compiler used for the build.
40
41  <platform> is the target platform (GOOS).
42
43  <arch> is the target architecture (GOARCH).
44`,
45		Run: func(cmd *cobra.Command, args []string) {
46			defer warnDeprecated()
47			env.Out.Printf("%s %s", execenv.RootCommandName, cmd.Root().Version)
48		},
49	}
50}
51
52// warnDeprecated warns about deprecated build variables
53// TODO: 0.12.0: remove support for old build tags
54func warnDeprecated() {
55	msg := "please contact your package maintainer"
56	reason := "deprecated build variable"
57	if GitLastTag != "" {
58		slog.Warn(msg, "reason", reason, "name", "GitLastTag", "value", GitLastTag)
59	}
60	if GitExactTag != "" {
61		slog.Warn(msg, "reason", reason, "name", "GitExactTag", "value", GitExactTag)
62	}
63	if GitCommit != "" {
64		slog.Warn(msg, "reason", reason, "name", "GitCommit", "value", GitCommit)
65	}
66}