Skip to content

Commit

Permalink
feat:add version flag to ldflags and print version in banner (#158)
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhartha Khuntia <siddharthakhuntia@gmail.com>
  • Loading branch information
sidkhuntia committed Nov 22, 2023
1 parent b948807 commit b7b9b22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ builds:
main: ./main.go
env:
- CGO_ENABLED=0
ldflags:
- -X github.com/yonahd/kor/pkg/utils.Version={{.Version}}
goos:
- linux
goarch:
Expand All @@ -17,6 +19,8 @@ builds:
main: ./main.go
env:
- CGO_ENABLED=0
ldflags:
- -X github.com/yonahd/kor/pkg/utils.Version={{.Version}}
goos:
- darwin
goarch:
Expand All @@ -32,7 +36,7 @@ builds:
- amd64
ldflags:
- -buildmode=exe

- -X github.com/yonahd/kor/pkg/utils.Version={{.Version}}
archives:
- format: tar.gz
name_template: >-
Expand All @@ -57,3 +61,5 @@ changelog:
- 'README'
- Merge pull request
- Merge branch
snapshot:
name_template: "{{ .Version }}"
6 changes: 5 additions & 1 deletion pkg/utils/banner.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package utils

import (
"fmt"

"github.com/fatih/color"
)

var Version = "dev"

func PrintLogo(outputFormat string) {
boldBlue := color.New(color.FgHiBlue, color.Bold)
asciiLogo := `
Expand All @@ -15,7 +19,7 @@ func PrintLogo(outputFormat string) {
`
// processing of the `outputFormat` happens inside of the rootCmd so this requires a pretty large change
// to keep the banner. Instead just loop through os args and find if the format was set and handle it there

fmt.Printf("version: v%s\n", Version)
if outputFormat != "yaml" && outputFormat != "json" {
boldBlue.Println(asciiLogo)
}
Expand Down

0 comments on commit b7b9b22

Please sign in to comment.