From ed24deee25fdaba1170a8a4a4f0dce91551d67cf Mon Sep 17 00:00:00 2001 From: Kornilios Kourtis Date: Tue, 30 Jan 2024 18:41:56 +0100 Subject: [PATCH] lvh: add version sub-command Signed-off-by: Kornilios Kourtis --- Makefile | 8 +++++++- cmd/lvh/main.go | 9 +++++++++ pkg/version/version.go | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 pkg/version/version.go diff --git a/Makefile b/Makefile index c393cea..fc974ac 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,12 @@ GO ?= go OCIREPO ?= quay.io/lvh-images/lvh DOCKER ?= docker +VERSION ?= $(shell git describe --tags --always --long) + +GO_BUILD_LDFLAGS = +GO_BUILD_LDFLAGS += -X 'github.com/cilium/little-vm-helper/pkg/version.Version=$(VERSION)' +GO_BUILD_FLAGS += -ldflags "$(GO_BUILD_LDFLAGS)" + all: tests little-vm-helper @@ -10,7 +16,7 @@ tests: $(GO) test -cover ./... little-vm-helper: FORCE - CGO_ENABLED=0 $(GO) build ./cmd/lvh + CGO_ENABLED=0 $(GO) build $(GO_BUILD_FLAGS) ./cmd/lvh .PHONY: image image: diff --git a/cmd/lvh/main.go b/cmd/lvh/main.go index c900ddd..8c27134 100644 --- a/cmd/lvh/main.go +++ b/cmd/lvh/main.go @@ -4,11 +4,13 @@ package main import ( + "fmt" "os" "github.com/cilium/little-vm-helper/cmd/lvh/images" "github.com/cilium/little-vm-helper/cmd/lvh/kernels" "github.com/cilium/little-vm-helper/cmd/lvh/runner" + "github.com/cilium/little-vm-helper/pkg/version" "github.com/spf13/cobra" ) @@ -26,6 +28,13 @@ func init() { images.ImagesCommand(), kernels.KernelsCommand(), runner.RunCommand(), + &cobra.Command{ + Use: "version", + Short: "version", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(version.Version) + }, + }, ) } diff --git a/pkg/version/version.go b/pkg/version/version.go new file mode 100644 index 0000000..a2a2835 --- /dev/null +++ b/pkg/version/version.go @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Authors of Cilium + +package version + +var Version string