This commit is contained in:
admju 2024-09-18 09:09:21 +00:00
parent 3abf53ec6c
commit 0c35993122
3 changed files with 47 additions and 8 deletions

View File

@ -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

View File

@ -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())

View File

@ -10,7 +10,6 @@ func main() {
log.InitLog(".oc-deploy")
log.Log().Debug().Msg("Start")
log.Log().Info().Msg("oc-deploy :")
cmd.Execute()