From f964b16e8a9d3d1d343df7ac5ba5844166e9580a Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 10 Jun 2022 14:31:49 +0200 Subject: [PATCH 1/3] refactor --- main.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index fe7a65a..ab6ce21 100644 --- a/main.go +++ b/main.go @@ -30,7 +30,7 @@ func main() { app.Usage = "command line tool to interact with Gitea" app.Description = appDescription app.CustomAppHelpTemplate = helpTemplate - app.Version = Version + formatBuiltWith(Tags) + app.Version = formatVersion() app.Commands = []*cli.Command{ &cmd.CmdLogin, &cmd.CmdLogout, @@ -61,12 +61,14 @@ func main() { } } -func formatBuiltWith(Tags string) string { +func formatVersion() string { + version := Version + if len(Tags) == 0 { - return "" + return version } - return " built with: " + strings.Replace(Tags, " ", ", ", -1) + return version + " built with: " + strings.Replace(Tags, " ", ", ", -1) } var appDescription = `tea is a productivity helper for Gitea. It can be used to manage most entities on -- 2.40.1 From 1180e2a83098a5162e180b15842376117882dc2b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 10 Jun 2022 14:47:07 +0200 Subject: [PATCH 2/3] add sdk version into version info --- Makefile | 3 ++- main.go | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 38246fd..9b65df1 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,8 @@ endif TEA_VERSION_TAG ?= $(shell sed 's/+/_/' <<< $(TEA_VERSION)) TAGS ?= -LDFLAGS := -X "main.Version=$(TEA_VERSION)" -X "main.Tags=$(TAGS)" -s -w +SDK ?= $(shell grep code.gitea.io/sdk/gitea go.mod | tr -d '\t' | cut -d ' ' -f 2) +LDFLAGS := -X "main.Version=$(TEA_VERSION)" -X "main.Tags=$(TAGS)" -X "main.SDK=$(SDK)" -s -w # override to allow passing additional goflags via make CLI override GOFLAGS := $(GOFLAGS) -mod=vendor -tags '$(TAGS)' -ldflags '$(LDFLAGS)' diff --git a/main.go b/main.go index ab6ce21..1fc60bb 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ package main // import "code.gitea.io/tea" import ( "fmt" "os" + "runtime" "strings" "code.gitea.io/tea/cmd" @@ -21,6 +22,9 @@ var Version = "development" // Tags holds the build tags used var Tags = "" +// SDK holds the sdk version from go.mod +var SDK = "" + func main() { // make parsing tea --version easier, by printing /just/ the version string cli.VersionPrinter = func(c *cli.Context) { fmt.Fprintln(c.App.Writer, c.App.Version) } @@ -62,13 +66,19 @@ func main() { } func formatVersion() string { - version := Version + version := fmt.Sprintf("Version: %s\tgolang: %s", + bold(Version), + strings.ReplaceAll(runtime.Version(), "go", "")) - if len(Tags) == 0 { - return version + if len(Tags) != 0 { + version += fmt.Sprintf("\tbuilt with: %s", strings.Replace(Tags, " ", ", ", -1)) } - return version + " built with: " + strings.Replace(Tags, " ", ", ", -1) + if len(SDK) != 0 { + version += fmt.Sprintf("\tgo-sdk: %s", SDK) + } + + return version } var appDescription = `tea is a productivity helper for Gitea. It can be used to manage most entities on -- 2.40.1 From 13cdcc36bd306258cf59175c8a803b81b93c874f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 18 Jun 2022 15:58:42 +0200 Subject: [PATCH 3/3] use go tooling --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9b65df1..f616587 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ endif TEA_VERSION_TAG ?= $(shell sed 's/+/_/' <<< $(TEA_VERSION)) TAGS ?= -SDK ?= $(shell grep code.gitea.io/sdk/gitea go.mod | tr -d '\t' | cut -d ' ' -f 2) +SDK ?= $(shell $(GO) list -f '{{.Version}}' -m code.gitea.io/sdk/gitea) LDFLAGS := -X "main.Version=$(TEA_VERSION)" -X "main.Tags=$(TAGS)" -X "main.SDK=$(SDK)" -s -w # override to allow passing additional goflags via make CLI -- 2.40.1