From e2094e54d03c1c18e94bbc8847bced20511503e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Rockst=C3=A4dt?= Date: Tue, 24 Jan 2023 08:51:34 +0100 Subject: [PATCH 1/2] Add version flag --- .github/workflows/binaries.yml | 3 ++- main.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/binaries.yml b/.github/workflows/binaries.yml index b7f0f6a..cc15041 100644 --- a/.github/workflows/binaries.yml +++ b/.github/workflows/binaries.yml @@ -27,4 +27,5 @@ jobs: goarch: ${{ matrix.goarch }} goversion: 1.19 compress_assets: OFF - release_tag: ${{ steps.previoustag.outputs.tag }} \ No newline at end of file + release_tag: ${{ steps.previoustag.outputs.tag }} + ldflags: -X 'main.version=${{ steps.previoustag.outputs.tag }}' \ No newline at end of file diff --git a/main.go b/main.go index 8d4e5a0..aa5455b 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "flag" + "fmt" "github.com/rockstaedt/txtreader" "log" "os" @@ -12,7 +14,17 @@ const ( hardLimit = 72 ) +var version string + func main() { + versionPtr := flag.Bool("v", false, "Prints the current version of the executable") + flag.Parse() + + if *versionPtr { + fmt.Println(version) + return + } + log.Println("[INFO]\t Validating commit message...") commitLines, err := txtreader.GetLinesFromTextFile(os.Args[1]) if err != nil { From 52d2ab9b8af1474ca6e11ce0a5590888c7b112be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Rockst=C3=A4dt?= Date: Tue, 24 Jan 2023 09:26:37 +0100 Subject: [PATCH 2/2] Use os exit to stop the executable --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index aa5455b..ed90915 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,7 @@ func main() { if *versionPtr { fmt.Println(version) - return + os.Exit(0) } log.Println("[INFO]\t Validating commit message...")