From ce9bb542ac2d54d9969ad4a805fcb6db69f8bdf0 Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Thu, 23 Feb 2023 10:55:07 -0800 Subject: [PATCH] add version command --- .goreleaser.yml | 2 ++ Makefile | 2 +- internal/cmd/util.go | 1 - internal/cmd/version.go | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 internal/cmd/version.go diff --git a/.goreleaser.yml b/.goreleaser.yml index 86b6180..74856d2 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -10,6 +10,8 @@ builds: - darwin goarch: - amd64 + ldflags: + - -s -w -X github.com/chriskim06/kubectl-topui/internal/cmd.tag={{.Version}} archives: - builds: - kubectl-topui diff --git a/Makefile b/Makefile index 1aa8a96..bdaae4e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ build: - go build -o out/kubectl-topui + go build -ldflags "-s -w -X github.com/chriskim06/kubectl-topui/internal/cmd.tag=DEV" -o out/kubectl-topui clean: rm -r out diff --git a/internal/cmd/util.go b/internal/cmd/util.go index 63e68b8..cf7fbae 100644 --- a/internal/cmd/util.go +++ b/internal/cmd/util.go @@ -29,7 +29,6 @@ Keyboard Shortcuts: - q: quit - j: scroll down - k: scroll up - - ?: display help modal - enter: view spec for selected item` ) diff --git a/internal/cmd/version.go b/internal/cmd/version.go new file mode 100644 index 0000000..24e093d --- /dev/null +++ b/internal/cmd/version.go @@ -0,0 +1,40 @@ +/* +Copyright © 2020 Chris Kim + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + // set by goreleaser via ldflags + tag string + + versionCmd = &cobra.Command{ + Use: "version", + Short: "Show topui version", + RunE: func(_ *cobra.Command, args []string) error { + fmt.Printf("v%s\n", tag) + return nil + }, + } +) + +func init() { + rootCmd.AddCommand(versionCmd) +}