From aa0254d2eb8cfb89d594861dcb3c9af2b0cf2b89 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Fri, 18 Aug 2023 13:51:06 -0700 Subject: Simplify main and version --- Makefile | 4 ++-- clientmain.go | 4 ++-- cmd/client/client.go | 7 ++++--- main.go | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 99748de..339b5c8 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ $(SERVER_BINARY): $(SERVER_FILES) @mkdir clients/ || true @touch clients/keep CGO_ENABLED=0 go build \ - -ldflags "-X main.appVersion=$(shell git describe --long --tags --dirty --always) \ + -ldflags "-X main.version=$(shell git describe --long --tags --dirty --always) \ -X code.crute.us/mcrute/ssh-proxy/cmd/client.clientId=$(CLIENT_ID)" \ -o $@ @@ -19,7 +19,7 @@ client: CGO_ENABLED=0 go build \ -tags clientonly \ - -ldflags "-X main.appVersion=$(shell git describe --long --tags --dirty --always) \ + -ldflags "-X main.version=$(shell git describe --long --tags --dirty --always) \ -X code.crute.us/mcrute/ssh-proxy/cmd/client.clientId=$(CLIENT_ID) \ -s -w" \ -o $(OUTFILE) diff --git a/clientmain.go b/clientmain.go index 91fcae0..a006feb 100644 --- a/clientmain.go +++ b/clientmain.go @@ -12,10 +12,10 @@ import ( _ "time/tzdata" ) -var appVersion string +var version string func main() { - cmd := client.NewClientCommand(appVersion) + cmd := client.NewClientCommand(version) if err := cmd.Execute(); err != nil { log.Fatalf("Error running root command: %s", err) diff --git a/cmd/client/client.go b/cmd/client/client.go index 1115673..54d7190 100644 --- a/cmd/client/client.go +++ b/cmd/client/client.go @@ -28,9 +28,10 @@ var clientId string func NewClientCommand(appVersion string) *cobra.Command { clientCmd := &cobra.Command{ - Use: "client proxy-host ssh-to-host ssh-port username", - Short: fmt.Sprintf("Run websocket client (version %s)", appVersion), - Args: cobra.ExactArgs(3), + Use: "client proxy-host ssh-to-host ssh-port username", + Short: "Run websocket client", + Args: cobra.ExactArgs(3), + Version: appVersion, Run: func(c *cobra.Command, args []string) { cfg := app.Config{} cli.MustGetConfig(c, &cfg) diff --git a/main.go b/main.go index fd2de2c..81863d0 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,6 @@ package main import ( "embed" - "fmt" "log" "code.crute.us/mcrute/ssh-proxy/app" @@ -32,8 +31,9 @@ var version string func main() { r := &cobra.Command{ - Use: "web-server", - Short: fmt.Sprintf("SSH proxy web server (version %s)", version), + Use: "web-server", + Short: "SSH proxy web server", + Version: version, } cli.AddFlags(r, &app.Config{}, app.DefaultConfig, "") -- cgit v1.2.3