diff --git a/.goreleaser.yml b/.goreleaser.yml index cea0d93..34eb904 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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 diff --git a/internal/commands/default.go b/internal/commands/default.go index 359ccd2..fd48c22 100644 --- a/internal/commands/default.go +++ b/internal/commands/default.go @@ -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() @@ -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 { @@ -40,6 +46,8 @@ 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)) @@ -47,3 +55,7 @@ func NewDefaultCommand() *cobra.Command { return &cmd } + +func GetVersion() string { + return version +}