Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ builds:
goarch:
- arm64
- amd64
ldflags:
- -X github.com/redhat-appstudio/tssc-cli/pkg/constants.Version={{.Version}}
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ INSTALLER_TARBALL_DATA ?= $(shell find -L $(INSTALLER_DIR) -type f \
! -name embed.go \
)

# Version will be set at build time via git describe
VERSION ?= $(shell \
if [ -n "$(GITHUB_REF_NAME)" ]; then echo "${GITHUB_REF_NAME}"; \
else git describe --tags --always || echo "v0.0.0-SNAPSHOT"; \
fi)

.EXPORT_ALL_VARIABLES:

.default: build
Expand All @@ -63,7 +69,7 @@ INSTALLER_TARBALL_DATA ?= $(shell find -L $(INSTALLER_DIR) -type f \
$(BIN): installer-tarball
@echo "# Building '$(BIN)'"
@[ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR)
go build -o $(BIN) $(CMD) $(ARGS)
go build -ldflags "-X github.com/redhat-appstudio/tssc-cli/pkg/constants.Version=$(VERSION)" -o $(BIN) $(CMD)

.PHONY: build
build: $(BIN)
Expand Down
9 changes: 9 additions & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ type RootCmd struct {
// Cmd exposes the root command, while instantiating the subcommand and their
// requirements.
func (r *RootCmd) Cmd() *cobra.Command {
// Handle version flag
r.cmd.RunE = func(cmd *cobra.Command, args []string) error {
if r.flags.Version {
r.flags.ShowVersion()
return nil
}
return cmd.Help()
}

logger := r.flags.GetLogger(os.Stdout)

r.cmd.AddCommand(subcmd.NewIntegration(logger, r.kube))
Expand Down
3 changes: 3 additions & 0 deletions pkg/constants/contants.go → pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ var (
// RepoURI is the reverse repository URI for the application.
RepoURI = fmt.Sprintf("%s.%s.%s", AppName, OrgName, Domain)
)

// Version is the application version, set at build time via ldflags.
var Version = "v0.0.0-SNAPSHOT"
9 changes: 9 additions & 0 deletions pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/redhat-appstudio/tssc-cli/pkg/constants"
"github.com/spf13/pflag"
)

Expand All @@ -20,12 +21,14 @@ type Flags struct {
KubeConfigPath string // path to the kubeconfig file
LogLevel *slog.Level // log verbosity level
Timeout time.Duration // helm client timeout
Version bool // show version
}

// PersistentFlags sets up the global flags.
func (f *Flags) PersistentFlags(p *pflag.FlagSet) {
p.BoolVar(&f.Debug, "debug", f.Debug, "enable debug mode")
p.BoolVar(&f.DryRun, "dry-run", f.DryRun, "enable dry-run mode")
p.BoolVar(&f.Version, "version", f.Version, "show the application version")
p.StringVar(
&f.KubeConfigPath,
"kube-config",
Expand Down Expand Up @@ -61,6 +64,11 @@ func (f *Flags) LoggerWith(l *slog.Logger) *slog.Logger {
return l.With("debug", f.Debug, "dry-run", f.DryRun, "timeout", f.Timeout)
}

// ShowVersion shows the application version and exits
func (f *Flags) ShowVersion() {
fmt.Printf("%s %s\n", constants.AppName, constants.Version)
}
Comment on lines +67 to +70
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Update the comment to reflect that the function no longer exits.

Good work addressing the past review feedback by removing os.Exit(0). However, the comment on Line 67 still states "shows the application version and exits" but the function now only prints without exiting.

Apply this diff to update the comment:

-// ShowVersion shows the application version and exits
+// ShowVersion prints the application version
 func (f *Flags) ShowVersion() {
 	fmt.Printf("%s %s\n", constants.AppName, constants.Version)
 }

Note: The past review concern about removing os.Exit(0) has been properly addressed.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// ShowVersion shows the application version and exits
func (f *Flags) ShowVersion() {
fmt.Printf("%s %s\n", constants.AppName, constants.Version)
}
// ShowVersion prints the application version
func (f *Flags) ShowVersion() {
fmt.Printf("%s %s\n", constants.AppName, constants.Version)
}
🤖 Prompt for AI Agents
In pkg/flags/flags.go around lines 67 to 70 the function comment still reads
"ShowVersion shows the application version and exits" even though the function
no longer calls os.Exit; update the comment to reflect that it only prints the
application/version information (e.g., "ShowVersion prints the application
version") so the comment matches the current behavior.


// NewFlags instantiates the global flags with default values.
func NewFlags() *Flags {
// Getting the current user configuration, later on the home directory is used
Expand All @@ -81,5 +89,6 @@ func NewFlags() *Flags {
KubeConfigPath: kubeConfigPath,
LogLevel: &defaultLogLevel,
Timeout: 15 * time.Minute,
Version: false,
}
}