Skip to content

Commit

Permalink
feat: add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnaduttPanchagnula authored and mcombuechen committed Mar 1, 2024
1 parent af7b7a7 commit 9f7c56a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ builds:
ldflags:
- "-s"
- "-w"
# - "-X github.com/snyk/parlay/internal/commands.version={{.Version}}"
- "-X github.com/snyk/parlay/internal/commands.version={{.Version}}"

archives:
- format: tar.gz
Expand Down
12 changes: 12 additions & 0 deletions internal/commands/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
"github.com/snyk/parlay/internal/commands/snyk"
)

// These values are set at build time
var (
version = ""
)

func NewDefaultCommand() *cobra.Command {
output := zerolog.ConsoleWriter{Out: os.Stderr}
logger := zerolog.New(output).With().Timestamp().Logger()
Expand All @@ -21,6 +26,7 @@ func NewDefaultCommand() *cobra.Command {
Use: "parlay",
Short: "Enrich an SBOM with context from third party services",
SilenceUsage: true,
Version: GetVersion(),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
if err := cmd.Help(); err != nil {
Expand All @@ -40,10 +46,16 @@ func NewDefaultCommand() *cobra.Command {
cmd.PersistentFlags().Bool("debug", false, "")
viper.BindPFlag("debug", cmd.PersistentFlags().Lookup("debug")) //nolint:errcheck

cmd.SetVersionTemplate(`{{.Version}}`)

cmd.AddCommand(ecosystems.NewEcosystemsRootCommand(logger))
cmd.AddCommand(snyk.NewSnykRootCommand(logger))
cmd.AddCommand(deps.NewDepsRootCommand(logger))
cmd.AddCommand(scorecard.NewRootCommand(logger))

return &cmd
}

func GetVersion() string {
return version
}

0 comments on commit 9f7c56a

Please sign in to comment.