Skip to content

Commit

Permalink
add version subcommand to csmctl
Browse files Browse the repository at this point in the history
Signed-off-by: Anurag <anurag.kumar@syself.com>
  • Loading branch information
kranurag7 committed Feb 23, 2024
1 parent ad4eac7 commit a91cd91
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ builds:
- binary: csctl
goos:
- linux
- darwin
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ldflags: -w -s -X github.com/SovereignCloudStack/csmctl/pkg/cmd.Version={{.Version}} -X github.com/SovereignCloudStack/csmctl/pkg/cmd.Commit={{.Commit}}
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ ARCH ?= amd64
IMAGE_PREFIX ?= ghcr.io/sovereigncloudstack
BUILDER_IMAGE = $(IMAGE_PREFIX)/csctl-builder
BUILDER_IMAGE_VERSION = $(shell cat .builder-image-version.txt)
Version := $(shell git describe --tags --always --dirty)
Commit := $(shell git rev-parse HEAD)
LDFLAGS := -X github.com/SovereignCloudStack/csmctl/pkg/cmd.Version=$(Version) -X github.com/SovereignCloudStack/csmctl/pkg/cmd.Commit=$(Commit)

# Certain aspects of the build are done in containers for consistency (e.g. protobuf generation)
# If you have the correct tools installed and you want to speed up development you can run
Expand All @@ -39,13 +42,23 @@ TOOLS_BIN_DIR := $(TOOLS_DIR)/$(BIN_DIR)
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
export GOBIN := $(abspath $(TOOLS_BIN_DIR))

##@ Clean
#########
# Clean #
#########

.PHONY: clean
clean: ## cleans the csmctl binary
@if [ -f csmctl ]; then rm csmctl; fi


##@ Common
##########
# Common #
##########
.PHONY: build
build: ## build the csctl binary
go build -o csctl main.go
build: # build the csmctl binary
go build -ldflags "$(LDFLAGS)" -o csmctl main.go

.PHONY: lint-golang
lint-golang: ## Lint Golang codebase
Expand Down
16 changes: 16 additions & 0 deletions pkg/clusterstack/mode.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package clusterstack

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ func Execute() {

func init() {
rootCmd.AddCommand(createCmd)
rootCmd.AddCommand(versionCmd)
}
42 changes: 42 additions & 0 deletions pkg/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var (
// Version of csctl.
Version = "dev"
// Commit against which csctl version is cut.
Commit = "unknown"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "prints the latest version of csmctl",
Run: printVersion,
SilenceUsage: true,
}

func printVersion(_ *cobra.Command, _ []string) {
fmt.Println("csmctl version:", Version)
fmt.Println("commit:", Commit)
}
2 changes: 1 addition & 1 deletion pkg/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type CustomWalkFunc func(src, dst, path string, info os.FileInfo, meta *csctlclu

// MyWalk is the custom walking function to walk in the cluster stacks.
func MyWalk(src, dst string, walkFn CustomWalkFunc, meta *csctlclusterstack.MetaData) error {
if err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err := filepath.Walk(src, func(path string, info os.FileInfo, _ error) error {
return walkFn(src, dst, path, info, meta)
}); err != nil {
return fmt.Errorf("failed to walk files: %w", err)
Expand Down

0 comments on commit a91cd91

Please sign in to comment.