From 0c35993122f5db0d29900ab3197a44eae7281f75 Mon Sep 17 00:00:00 2001 From: admju Date: Wed, 18 Sep 2024 09:09:21 +0000 Subject: [PATCH] Version --- src/Makefile | 34 ++++++++++++++++++++++++++++------ src/cmd/args.go | 20 +++++++++++++++++++- src/main.go | 1 - 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/Makefile b/src/Makefile index 3d3b438..f3f7465 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,6 +11,16 @@ BIN_DIR = ../bin/ PLUGINS := $(wildcard ../plugins/*/*.go) OBJS := ${PLUGINS:.go=.so} +################## +DATE := $(shell date) +GOVERSION := $(shell go version) +VERSION := $(shell git describe --tags --abbrev=8 --dirty --always --long) +PREFIX := "oc-deploy/version" + +LDFLAGS := -X '${PREFIX}.Version=${VERSION}' + +################## + %.so: %.go go build -buildmode=plugin -o $@ $< @@ -23,35 +33,44 @@ help: @echo ' make run BIN_OPTS=... Go run' @echo ' make run_install BIN_OPTS=... Go run' @echo ' make run_uninstall BIN_OPTS=... Go run' + @echo ' make run_version Go run' @echo ' make exec BIN_OPTS=... exécutable' @echo ' make exec_install BIN_OPTS=... exécutable' @echo ' make exec_uninstall BIN_OPTS=... exécutable' - @echo ' make test Test.' + @echo ' make exec_version exécutable' @echo ' make test Test' @echo ' make clean Clean the directory tree.' @echo + @echo ' DATE ${DATE}' + @echo ' GOVERSION ${GOVERSION}' + @echo ' VERSION ${VERSION}' + @echo + ${BIN_DIR}/${BIN_NAME}: ${SOURCES} $(OBJS) - go build -o ${BIN_DIR}/${BIN_NAME} + go build -o ${BIN_DIR}/${BIN_NAME} -ldflags "${LDFLAGS}" get-deps: @go mod tidy build: ${BIN_DIR}/${BIN_NAME} -run: $(OBJS) +run: @go run main.go ${BIN_OPTS} -run_generate: $(OBJS) +run_generate: @go run main.go generate ${BIN_OPTS} -run_install: $(OBJS) +run_install: @go run main.go install ${BIN_OPTS} -run_uninstall: $(OBJS) +run_uninstall: @go run main.go uninstall ${BIN_OPTS} +run_version: + @go run main.go version + exec: ${BIN_DIR}/${BIN_NAME} $(OBJS) @${BIN_DIR}/${BIN_NAME} ${BIN_OPTS} @@ -61,6 +80,9 @@ exec_install: ${BIN_DIR}/${BIN_NAME} $(OBJS) exec_uninstall: ${BIN_DIR}/${BIN_NAME} $(OBJS) @${BIN_DIR}/${BIN_NAME} uninstall ${BIN_OPTS} +exec_version: ${BIN_DIR}/${BIN_NAME} $(OBJS) + @${BIN_DIR}/${BIN_NAME} version + clean: @test ! -e ${BIN_DIR}/${BIN_NAME} || rm ${BIN_DIR}/${BIN_NAME} @test ! -e .coverage.out || rm .coverage.out diff --git a/src/cmd/args.go b/src/cmd/args.go index 7a479fc..d15812d 100644 --- a/src/cmd/args.go +++ b/src/cmd/args.go @@ -24,6 +24,7 @@ func cobraInstallCmd() *cobra.Command { Long: `deploy Charts`, Args: cobra.MaximumNArgs(0), RunE: func(cmd *cobra.Command, args []string) error { + log.Log().Info().Msg("oc-deploy :") return InstallCmd(context, version, modules) }, Example: "oc-deploy install --version 0.1.0 --context ex1", @@ -37,6 +38,7 @@ func cobraUninstallCmd() *cobra.Command{ Long: `Undeploy`, Args: cobra.MaximumNArgs(0), RunE: func(cmd *cobra.Command, args []string) error { + log.Log().Info().Msg("oc-deploy :") return UninstallCmd(context) }, Example: "oc-deploy uninstall --context ex1", @@ -48,15 +50,29 @@ func cobraGenerateCmd() *cobra.Command{ return &cobra.Command{ Use: "generate", Short: "generate", - Long: "Value", + Long: "generate", Args: cobra.MaximumNArgs(0), RunE: func(cmd *cobra.Command, args []string) error { + log.Log().Info().Msg("oc-deploy :") return GenerateCmd(context, version) }, Example: "oc-deploy generate --version 0.1.0 --context ex1", } } +func cobraVersionCmd() *cobra.Command{ + return &cobra.Command{ + Use: "version", + Short: "version", + Long: "Get Version", + Args: cobra.MaximumNArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + return VersionCmd() + }, + Example: "oc-deploy version", + } +} + func Execute() { log.Log().Debug().Msg("Execute") @@ -66,6 +82,7 @@ func Execute() { var cmdInstall = cobraInstallCmd() var cmdUninstall = cobraUninstallCmd() var cmdGenerate = cobraGenerateCmd() + var cmdVersion = cobraVersionCmd() cmdInstall.Flags().StringVarP(&context, "context", "c", "opencloud", "Nom du context") cmdInstall.Flags().StringVarP(&version, "version", "v", "latest", "Version") @@ -79,6 +96,7 @@ func Execute() { rootCmd.AddCommand(cmdInstall) rootCmd.AddCommand(cmdUninstall) rootCmd.AddCommand(cmdGenerate) + rootCmd.AddCommand(cmdVersion) cobra.CheckErr(rootCmd.Execute()) diff --git a/src/main.go b/src/main.go index daee0be..81ea688 100644 --- a/src/main.go +++ b/src/main.go @@ -10,7 +10,6 @@ func main() { log.InitLog(".oc-deploy") log.Log().Debug().Msg("Start") - log.Log().Info().Msg("oc-deploy :") cmd.Execute()