From c5041d5c3eda9c598c3059ef093b9394b3d7655a Mon Sep 17 00:00:00 2001 From: Johan Dewe Date: Thu, 30 Sep 2021 13:40:24 +0200 Subject: [PATCH] Add version command showing current sinker version --- Makefile | 4 ++-- internal/commands/default.go | 1 + internal/commands/version.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 internal/commands/version.go diff --git a/Makefile b/Makefile index 8ca5fbd..94c7d9e 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ .PHONY: build build: - @go build + @go build -ldflags="-X 'github.com/plexsystems/sinker/internal/commands.sinkerVersion=$$(git describe --tags --always --dirty)'" -.PHONY: test +.PHONY: test test: @go test -v ./... -count=1 diff --git a/internal/commands/default.go b/internal/commands/default.go index 86c5f40..d938a31 100644 --- a/internal/commands/default.go +++ b/internal/commands/default.go @@ -34,6 +34,7 @@ func NewDefaultCommand() *cobra.Command { cmd.AddCommand(newPullCommand()) cmd.AddCommand(newPushCommand()) cmd.AddCommand(newCheckCommand()) + cmd.AddCommand(newVersionCommand()) return &cmd } diff --git a/internal/commands/version.go b/internal/commands/version.go new file mode 100644 index 0000000..aa9512e --- /dev/null +++ b/internal/commands/version.go @@ -0,0 +1,31 @@ +package commands + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +func newVersionCommand() *cobra.Command { + cmd := cobra.Command{ + Use: "version", + Short: "The version of sinker", + + RunE: func(cmd *cobra.Command, args []string) error { + if err := runVersionCommand(); err != nil { + return fmt.Errorf("list: %w", err) + } + + return nil + }, + } + + cmd.Flags().StringP("output", "o", "", "Output the images in the manifest to a file") + + return &cmd +} + +func runVersionCommand() error { + fmt.Println("sinker version " + sinkerVersion) + return nil +}