Skip to content

Commit

Permalink
Add a "-version" flag to both binaries, via goreleaser ldflags. (#8)
Browse files Browse the repository at this point in the history
* Testing version ldflag

* Add -version flag to show version of each binary.

* Exit code 0
  • Loading branch information
tiegz authored Aug 29, 2024
1 parent 406844d commit 873ce6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/tidelift-sbom-analyzer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -33,6 +41,11 @@ func main() {

flag.Parse()

if printVersion {
fmt.Println(version)
os.Exit(0)
}

if _, keyExists := os.LookupEnv("TIDELIFT_API_KEY"); !keyExists {
log.Fatalf("Error: TIDELIFT_API_KEY environment variable is required.")
}
Expand Down
12 changes: 12 additions & 0 deletions cmd/tidelift-sbom-vulnerability-reporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +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"
)

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 JSON file containing vulnerabilities from Tidelift for the packages in an SBOM.")
Expand All @@ -57,6 +64,11 @@ func main() {

flag.Parse()

if printVersion {
fmt.Println(version)
os.Exit(0)
}

if _, keyExists := os.LookupEnv("TIDELIFT_API_KEY"); !keyExists {
log.Fatalf("Error: TIDELIFT_API_KEY environment variable is required.")
}
Expand Down

0 comments on commit 873ce6c

Please sign in to comment.