From 3baea70508ff3996549f21826e426d2ee4b28d9a Mon Sep 17 00:00:00 2001 From: Andrew Davis <1709934+Savid@users.noreply.github.com> Date: Mon, 7 Oct 2024 09:39:07 +1000 Subject: [PATCH] feat(cmd/version): add version command --- .goreleaser.yaml | 10 +++++----- cmd/version.go | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 cmd/version.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index daff8389..4c70fc30 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -16,7 +16,7 @@ builds: goarch: - amd64 ldflags: - - -s -w -X github.com/ethpandaops/xatu/pkg/proto/xatu.Release={{.Tag}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GitCommit={{.ShortCommit}} + - -s -w -X github.com/ethpandaops/xatu/pkg/proto/xatu.Release={{.Tag}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GitCommit={{.ShortCommit}} -X github.com/ethpandaops/xatu/cmd.release={{.Tag}} -X github.com/ethpandaops/xatu/cmd.commit={{.ShortCommit}} -X github.com/ethpandaops/xatu/cmd.platform={{.GOOS}}/{{.GOARCH}} mod_timestamp: "{{ .CommitTimestamp }}" - id: linux-arm64 @@ -30,7 +30,7 @@ builds: goarch: - arm64 ldflags: - - -s -w -X github.com/ethpandaops/xatu/pkg/proto/xatu.Release={{.Tag}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GitCommit={{.ShortCommit}} + - -s -w -X github.com/ethpandaops/xatu/pkg/proto/xatu.Release={{.Tag}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GitCommit={{.ShortCommit}} -X github.com/ethpandaops/xatu/cmd.release={{.Tag}} -X github.com/ethpandaops/xatu/cmd.commit={{.ShortCommit}} -X github.com/ethpandaops/xatu/cmd.platform={{.GOOS}}/{{.GOARCH}} mod_timestamp: "{{ .CommitTimestamp }}" - id: windows-amd64 @@ -44,7 +44,7 @@ builds: goarch: - amd64 ldflags: - - -s -w -X github.com/ethpandaops/xatu/pkg/proto/xatu.Release={{.Tag}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GitCommit={{.ShortCommit}} + - -s -w -X github.com/ethpandaops/xatu/pkg/proto/xatu.Release={{.Tag}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GitCommit={{.ShortCommit}} -X github.com/ethpandaops/xatu/cmd.release={{.Tag}} -X github.com/ethpandaops/xatu/cmd.commit={{.ShortCommit}} -X github.com/ethpandaops/xatu/cmd.platform={{.GOOS}}/{{.GOARCH}} mod_timestamp: "{{ .CommitTimestamp }}" - id: darwin-amd64 @@ -58,7 +58,7 @@ builds: goarch: - amd64 ldflags: - - -s -w -X github.com/ethpandaops/xatu/pkg/proto/xatu.Release={{.Tag}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GitCommit={{.ShortCommit}} + - -s -w -X github.com/ethpandaops/xatu/pkg/proto/xatu.Release={{.Tag}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GitCommit={{.ShortCommit}} -X github.com/ethpandaops/xatu/cmd.release={{.Tag}} -X github.com/ethpandaops/xatu/cmd.commit={{.ShortCommit}} -X github.com/ethpandaops/xatu/cmd.platform={{.GOOS}}/{{.GOARCH}} mod_timestamp: "{{ .CommitTimestamp }}" - id: darwin-arm64 @@ -72,7 +72,7 @@ builds: goarch: - arm64 ldflags: - - -s -w -X github.com/ethpandaops/xatu/pkg/proto/xatu.Release={{.Tag}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GitCommit={{.ShortCommit}} + - -s -w -X github.com/ethpandaops/xatu/pkg/proto/xatu.Release={{.Tag}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GitCommit={{.ShortCommit}} -X github.com/ethpandaops/xatu/cmd.release={{.Tag}} -X github.com/ethpandaops/xatu/cmd.commit={{.ShortCommit}} -X github.com/ethpandaops/xatu/cmd.platform={{.GOOS}}/{{.GOARCH}} mod_timestamp: "{{ .CommitTimestamp }}" checksum: name_template: 'checksums.txt' diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 00000000..b347df01 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + release = "dev" + commit = "unknown" + platform = "unknown" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Prints the version of Xatu.", + Long: `Prints the version of Xatu.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("xatu version %s %s %s\n", version, commit, platform) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +}