From 559a071345a4c87eb06c666f12496a0bf624f5ba Mon Sep 17 00:00:00 2001 From: Tieg Zaharia Date: Wed, 28 Aug 2024 14:31:04 -0600 Subject: [PATCH] Add -version flag to show version of each binary. --- cmd/tidelift-sbom-analyzer/main.go | 13 +++++++++++++ cmd/tidelift-sbom-vulnerability-reporter/main.go | 13 ++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cmd/tidelift-sbom-analyzer/main.go b/cmd/tidelift-sbom-analyzer/main.go index 43a9799..6d83ed5 100644 --- a/cmd/tidelift-sbom-analyzer/main.go +++ b/cmd/tidelift-sbom-analyzer/main.go @@ -15,11 +15,19 @@ import ( utils "github.com/tidelift/tidelift-sbom-info/internal/utils" ) +// This gets overwritten by goreleaser with the git tag, during a release. +var ( + version = "dev" +) + func main() { var debug bool var outputFile string + var printVersion bool + flag.BoolVar(&debug, "debug", false, "Show debug logging") flag.StringVar(&outputFile, "output", "", "Write output to a file (defaults to stdout)") + flag.BoolVar(&printVersion, "version", false, "Show version information") flag.Usage = func() { fmt.Fprintln(flag.CommandLine.Output(), "Display a CSV containing recommendations from Tidelift for the packages in an SBOM.") @@ -33,6 +41,11 @@ func main() { flag.Parse() + if printVersion { + fmt.Println(version) + os.Exit(1) + } + if _, keyExists := os.LookupEnv("TIDELIFT_API_KEY"); !keyExists { log.Fatalf("Error: TIDELIFT_API_KEY environment variable is required.") } diff --git a/cmd/tidelift-sbom-vulnerability-reporter/main.go b/cmd/tidelift-sbom-vulnerability-reporter/main.go index 3812c60..86bdf05 100644 --- a/cmd/tidelift-sbom-vulnerability-reporter/main.go +++ b/cmd/tidelift-sbom-vulnerability-reporter/main.go @@ -38,21 +38,19 @@ type VulnerabilityDetails struct { RecommendationDetails *RecommendationDetails `json:"recommendation_details"` } +// This gets overwritten by goreleaser with the git tag, during a release. var ( version = "dev" - commit = "none" - date = "unknown" ) func main() { - - fmt.Printf("my app %s, commit %s, built at %s", version, commit, date) - var debug bool var outputFile string + var printVersion bool flag.BoolVar(&debug, "debug", false, "Show debug logging") flag.StringVar(&outputFile, "output", "", "Write output to a file (defaults to stdout)") + flag.BoolVar(&printVersion, "version", false, "Show version information") flag.Usage = func() { fmt.Fprintln(flag.CommandLine.Output(), "Display a JSON file containing vulnerabilities from Tidelift for the packages in an SBOM.") @@ -66,6 +64,11 @@ func main() { flag.Parse() + if printVersion { + fmt.Println(version) + os.Exit(1) + } + if _, keyExists := os.LookupEnv("TIDELIFT_API_KEY"); !keyExists { log.Fatalf("Error: TIDELIFT_API_KEY environment variable is required.") }