diff --git a/.goreleaser.yml b/.goreleaser.yml index bc86bfe..331ea7f 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -8,6 +8,8 @@ builds: goarch: - amd64 - arm64 + ldflags: + - -s -w -X github.com/itaysk/kubectl-neat/cmd.Version={{ .Version }} archives: - name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}" checksum: diff --git a/cmd/cmd.go b/cmd/cmd.go index cbbd80e..fce492a 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -37,6 +37,7 @@ func init() { rootCmd.SetErr(os.Stderr) rootCmd.MarkFlagFilename("file") rootCmd.AddCommand(getCmd) + rootCmd.AddCommand(versionCmd) } // Execute is the entry point for the command package @@ -127,6 +128,20 @@ kubectl neat get -- svc -n default myservice --output json`, }, } +// populated by goreleaser +var ( + Version = "v0.0.0+unknown" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print kubectl-neat version", + Long: "Print the version of kubectl-neat", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("kubectl-neat version: %s\n", Version) + }, +} + func isJSON(s []byte) bool { return bytes.HasPrefix(bytes.TrimLeftFunc(s, unicode.IsSpace), []byte{'{'}) }