Skip to content

Commit

Permalink
Add -version flag to show version of each binary.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiegz committed Aug 28, 2024
1 parent 268aa4a commit 559a071
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 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(1)
}

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

0 comments on commit 559a071

Please sign in to comment.