Skip to content

Commit 8a08887

Browse files
committed
added version command
1 parent a358139 commit 8a08887

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

.goreleaser.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ before:
1818
builds:
1919
- id: helm-values
2020
main: ./cmd/helm-values
21+
ldflags:
22+
- -s -w
23+
- -X main.BuildVersion={{ .Version }}
24+
- -X main.BuildCommit={{ .FullCommit }}
25+
- -X main.BuildDate={{ .Date }}
2126
env:
2227
- CGO_ENABLED=0
2328
goos:

cmd/helm-values/main.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"os"
56

67
"helmvalues/cmd/helm-values/internal/config"
@@ -11,6 +12,10 @@ import (
1112
"github.com/spf13/cobra"
1213
)
1314

15+
var BuildVersion string
16+
var BuildCommit string
17+
var BuildDate string
18+
1419
func main() {
1520
logger := logrus.New()
1621
logger.SetLevel(logrus.InfoLevel)
@@ -27,12 +32,13 @@ func Program(logger *logrus.Logger) *cobra.Command {
2732
Short: "Schema and docs generator for Helm values",
2833
}
2934
cmd.CompletionOptions.DisableDefaultCmd = true
30-
cmd.AddCommand(Schema(logger))
31-
cmd.AddCommand(Docs(logger))
35+
cmd.AddCommand(CommandSchema(logger))
36+
cmd.AddCommand(CommandDocs(logger))
37+
cmd.AddCommand(CommandVersion(logger))
3238
return cmd
3339
}
3440

35-
func Schema(logger *logrus.Logger) *cobra.Command {
41+
func CommandSchema(logger *logrus.Logger) *cobra.Command {
3642
cfg := config.NewSchemaConfig()
3743

3844
cmd := &cobra.Command{
@@ -56,7 +62,7 @@ func Schema(logger *logrus.Logger) *cobra.Command {
5662
return cmd
5763
}
5864

59-
func Docs(logger *logrus.Logger) *cobra.Command {
65+
func CommandDocs(logger *logrus.Logger) *cobra.Command {
6066
cfg := config.NewDocsConfig()
6167

6268
cmd := &cobra.Command{
@@ -80,3 +86,23 @@ func Docs(logger *logrus.Logger) *cobra.Command {
8086

8187
return cmd
8288
}
89+
90+
func CommandVersion(logger *logrus.Logger) *cobra.Command {
91+
cfg := config.NewDocsConfig()
92+
93+
cmd := &cobra.Command{
94+
Use: "version",
95+
Short: "Print version information",
96+
RunE: func(cmd *cobra.Command, args []string) error {
97+
fmt.Printf("helm-values\n\n")
98+
fmt.Printf(" Version: %s\n", BuildVersion)
99+
fmt.Printf(" Commit: %s\n", BuildCommit)
100+
fmt.Printf(" Date: %s\n", BuildDate)
101+
return nil
102+
},
103+
}
104+
105+
cfg.BindFlags(cmd)
106+
107+
return cmd
108+
}

0 commit comments

Comments
 (0)