Skip to content

Commit

Permalink
feat(cmd/version): add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
Savid committed Oct 6, 2024
1 parent c24535c commit 3baea70
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 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/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
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/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
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/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
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/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
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/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'
Expand Down
26 changes: 26 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -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)

Check failure on line 20 in cmd/version.go

View workflow job for this annotation

GitHub Actions / lint

undefined: version (typecheck)

Check failure on line 20 in cmd/version.go

View workflow job for this annotation

GitHub Actions / lint

undefined: version) (typecheck)

Check failure on line 20 in cmd/version.go

View workflow job for this annotation

GitHub Actions / full_ci (1.22.x)

undefined: version
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}

0 comments on commit 3baea70

Please sign in to comment.