Skip to content

Commit

Permalink
Merge pull request #386 from ethpandaops/release/version
Browse files Browse the repository at this point in the history
feat(cmd/version): add version command
  • Loading branch information
Savid authored Oct 7, 2024
2 parents c24535c + ae5960f commit fc7882a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
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("%s\n", xatu.FullVWithPlatform())
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
8 changes: 7 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,11 @@ func Short() string {
}

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

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

func ImplementationLower() string {
Expand Down

0 comments on commit fc7882a

Please sign in to comment.