From 0c2ab1063a57333a5e86d7554e042ef7795bbd22 Mon Sep 17 00:00:00 2001 From: Muhammed Can Kucukaslan Date: Sat, 30 Sep 2023 16:08:49 +0300 Subject: [PATCH] at least keep commit info in go install --- Readme.md | 8 +++++--- main.go | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Readme.md b/Readme.md index 96da5eb..a8bbef6 100644 --- a/Readme.md +++ b/Readme.md @@ -22,7 +22,10 @@ The following is the list of the flags and their functionalities. ## Installation -### go install +### Binaries +See [Releases](https://github.com/Kucukaslan/todo/releases) page for pre-built binaries. +### Building from source +#### go install ```bash go install github.com/kucukaslan/todo@latest @@ -30,7 +33,7 @@ go install github.com/kucukaslan/todo@latest or for a specific version ```bash -go install github.com/kucukaslan/todo@v0.4.2 +go install github.com/kucukaslan/todo@v0.1.4-alpha ``` you can list the available versions with @@ -38,7 +41,6 @@ you can list the available versions with go list -m -versions github.com/kucukaslan/todo ``` -### Building from source #### Windows Download the source code. Open the directory. diff --git a/main.go b/main.go index bfec75e..e8975f7 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ todo -d TODO-Id # delete item import ( "flag" "fmt" + "runtime/debug" ) var ( @@ -21,9 +22,47 @@ var ( version = "v0.0.0" // GitCommit represents git commit hash of a particular release. - commit = "dev" - date = "" - builtBy = "" + commit = func() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + return setting.Value + } + } + } + return "" + }() + date = func() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.time" { + return setting.Value + } + } + } + return "" + }() + builtBy = func() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs" { + return setting.Value + } + } + } + return "" + }() + + modified = func() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.modified" { + return setting.Value + } + } + } + return "" + }() ) func main() { @@ -73,7 +112,8 @@ func main() { } func printVersion() { - v := version + "-" + commit - fmt.Println("todo ", v, " built on", date," (by Muhammed Can Küçükaslan https://github.com/kucukaslan)") + v := version + "-" + commit + fmt.Println("todo ", v, "built on", date, "(via", builtBy, "; local modification: ", modified, ")") fmt.Println("There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") + fmt.Println("~ Muhammed Can Küçükaslan https://github.com/kucukaslan)") }