Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd/version): add version command #386

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/pkg/proto/xatu.GOOS={{.Runtime.Goos}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GOARCH={{.Runtime.Goarch}}
mod_timestamp: "{{ .CommitTimestamp }}"

- id: linux-arm64
Expand All @@ -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/pkg/proto/xatu.GOOS={{.Runtime.Goos}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GOARCH={{.Runtime.Goarch}}
mod_timestamp: "{{ .CommitTimestamp }}"

- id: windows-amd64
Expand All @@ -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/pkg/proto/xatu.GOOS={{.Runtime.Goos}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GOARCH={{.Runtime.Goarch}}
mod_timestamp: "{{ .CommitTimestamp }}"

- id: darwin-amd64
Expand All @@ -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/pkg/proto/xatu.GOOS={{.Runtime.Goos}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GOARCH={{.Runtime.Goarch}}
mod_timestamp: "{{ .CommitTimestamp }}"

- id: darwin-arm64
Expand All @@ -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/pkg/proto/xatu.GOOS={{.Runtime.Goos}} -X github.com/ethpandaops/xatu/pkg/proto/xatu.GOARCH={{.Runtime.Goarch}}
mod_timestamp: "{{ .CommitTimestamp }}"
checksum:
name_template: 'checksums.txt'
Expand Down
21 changes: 21 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"fmt"

"github.com/ethpandaops/xatu/pkg/proto/xatu"
"github.com/spf13/cobra"
)

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/%s\n", xatu.Release, xatu.GitCommit, xatu.GOOS, xatu.GOARCH)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
4 changes: 3 additions & 1 deletion pkg/proto/xatu/xatu.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var (
Release = "dev"
GitCommit = "dev"
Implementation = "Xatu"
GOOS = runtime.GOOS
GOARCH = runtime.GOARCH
)

func Full() string {
Expand All @@ -29,7 +31,7 @@ func Short() string {
}

func FullVWithGOOS() string {
return fmt.Sprintf("%s/%s", Full(), runtime.GOOS)
return fmt.Sprintf("%s/%s", Full(), GOOS)
}

func ImplementationLower() string {
Expand Down
Loading