Skip to content

Commit

Permalink
update && add Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyisan committed Sep 16, 2022
1 parent cf4c3d9 commit 7aa5068
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
.PHONY: build-linux build-osx build-windows clean

VERSION=$(shell git rev-parse --short HEAD)
BUILD=$(shell date +%FT%T%z)

build-linux:
@GOARCH=amd64 CGO_ENABLED=1 GOOS=linux go build -ldflags "-s -w" -o bin/kube-resource_linux
@GOARCH=amd64 CGO_ENABLED=1 GOOS=linux go build -ldflags "-s -w -X main.Version=${VERSION} -X main.Build=${BUILD}" -o bin/kube-resource_linux

build-osx:
@GOARCH=amd64 CGO_ENABLED=1 GOOS=darwin go build -ldflags "-s -w" -o bin/kube-resource_darwin
@GOARCH=amd64 CGO_ENABLED=1 GOOS=darwin go build -ldflags "-s -w -X main.Version=${VERSION} -X main.Build=${BUILD}" -o bin/kube-resource_darwin

build-windows:
@GOARCH=amd64 CGO_ENABLED=1 GOOS=windows go build -ldflags "-s -w" -o bin/kube-resource_windows
@GOARCH=amd64 CGO_ENABLED=1 GOOS=windows go build -ldflags "-s -w -X main.Version=${VERSION} -X main.Build=${BUILD}" -o bin/kube-resource_windows

clean:
@if [ -f bin/kube-resource_linux ] ; then rm bin/kube-resource_linux ; fi
Expand Down
5 changes: 1 addition & 4 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package config

import (
"github.com/spf13/pflag"
"os"
"path/filepath"
)

func InitKubeConfig() *string {
var kubeConfig *string
kubeConfig = pflag.StringP("kubeconfig", "c", "", "(optional) absolute path to the kubeconfig file")
func InitKubeConfig(kubeConfig *string) *string {
if *kubeConfig == "" {
if home := homeDir(); home != "" {
c := filepath.Join(home, ".kube", "config")
Expand Down
32 changes: 28 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,30 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"kubernetes-resource-list/config"
"os"
"strings"
)

var (
prefer *bool
kubeConfig = pflag.StringP("kubeconfig", "c", "", "(optional) absolute path to the kubeconfig file")
prefer = pflag.BoolP("prefer", "p", false, "(optional) only display the supported resources with the version preferred by the server.")
search = pflag.StringP("search", "s", "", "(optional) only display the supported resources for a group and version.")
version = pflag.BoolP("version", "v", false, "show app version")
Version string
Build string
)

func main() {
prefer = pflag.BoolP("prefer", "p", false, "(optional) only display the supported resources with the version preferred by the server.")
search := pflag.StringP("search", "s", "", "(optional) only display the supported resources for a group and version.")
c := config.InitKubeConfig()
pflag.Parse()

// init kubeconfig file
c := config.InitKubeConfig(kubeConfig)

// show app info
showInfo()

discoveryClient := newDiscoveryClient(*c)

if *search == "" {
getResources(discoveryClient)
} else {
Expand Down Expand Up @@ -100,3 +111,16 @@ func tableHeader() {
func searchTableHeader() {
fmt.Printf("%-35s\t%-s\n", "NAME", "VERBS")
}

func showInfo() {
if *version {
showAppInfo()
os.Exit(0)
}
}

func showAppInfo() {
fmt.Printf("Version:\t %s\n", Version)
fmt.Printf("Build:\t %s\n", Build)

}

0 comments on commit 7aa5068

Please sign in to comment.