Skip to content

Commit 3b2986a

Browse files
feat: add version command (#19)
Closes #15.
1 parent af7b7a7 commit 3b2986a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ builds:
2121
ldflags:
2222
- "-s"
2323
- "-w"
24-
# - "-X github.com/snyk/parlay/internal/commands.version={{.Version}}"
24+
- "-X github.com/snyk/parlay/internal/commands.version={{.Version}}"
2525

2626
archives:
2727
- format: tar.gz

internal/commands/default.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import (
1313
"github.com/snyk/parlay/internal/commands/snyk"
1414
)
1515

16+
// These values are set at build time
17+
var (
18+
version = ""
19+
)
20+
1621
func NewDefaultCommand() *cobra.Command {
1722
output := zerolog.ConsoleWriter{Out: os.Stderr}
1823
logger := zerolog.New(output).With().Timestamp().Logger()
@@ -21,6 +26,7 @@ func NewDefaultCommand() *cobra.Command {
2126
Use: "parlay",
2227
Short: "Enrich an SBOM with context from third party services",
2328
SilenceUsage: true,
29+
Version: GetVersion(),
2430
DisableFlagsInUseLine: true,
2531
Run: func(cmd *cobra.Command, args []string) {
2632
if err := cmd.Help(); err != nil {
@@ -40,10 +46,16 @@ func NewDefaultCommand() *cobra.Command {
4046
cmd.PersistentFlags().Bool("debug", false, "")
4147
viper.BindPFlag("debug", cmd.PersistentFlags().Lookup("debug")) //nolint:errcheck
4248

49+
cmd.SetVersionTemplate(`{{.Version}}`)
50+
4351
cmd.AddCommand(ecosystems.NewEcosystemsRootCommand(logger))
4452
cmd.AddCommand(snyk.NewSnykRootCommand(logger))
4553
cmd.AddCommand(deps.NewDepsRootCommand(logger))
4654
cmd.AddCommand(scorecard.NewRootCommand(logger))
4755

4856
return &cmd
4957
}
58+
59+
func GetVersion() string {
60+
return version
61+
}

0 commit comments

Comments
 (0)