From 2815a803232be479ee36aeff8a19f3898c060fbe Mon Sep 17 00:00:00 2001 From: George Tsiolis Date: Thu, 12 Mar 2026 14:06:59 +0200 Subject: [PATCH 1/5] Remove version command and simplify version output --- cmd/help_test.go | 1 + cmd/non_interactive_test.go | 4 ++-- cmd/root.go | 3 +-- cmd/version.go | 15 +++------------ cmd/version_test.go | 32 ++++++++++++++++++++++++-------- test/integration/update_test.go | 6 +++--- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/cmd/help_test.go b/cmd/help_test.go index d38fc59..e370a07 100644 --- a/cmd/help_test.go +++ b/cmd/help_test.go @@ -34,6 +34,7 @@ func TestRootHelpOutputTemplate(t *testing.T) { assertContains(t, out, "Options:") assertNotContains(t, out, "Available Commands:") assertNotContains(t, out, `Use "lstk [command] --help" for more information about a command.`) + assertNotContains(t, out, "\n version ") } func TestSubcommandHelpUsesSubcommandUsageLine(t *testing.T) { diff --git a/cmd/non_interactive_test.go b/cmd/non_interactive_test.go index 2ac1e52..a8bf5e7 100644 --- a/cmd/non_interactive_test.go +++ b/cmd/non_interactive_test.go @@ -47,7 +47,7 @@ func TestNonInteractiveFlagAppearsInStopHelp(t *testing.T) { func TestNonInteractiveFlagBindsToCfg(t *testing.T) { cfg := &env.Env{} root := NewRootCmd(cfg, telemetry.New("", true)) - root.SetArgs([]string{"--non-interactive", "version"}) + root.SetArgs([]string{"--non-interactive", "--version"}) _ = root.Execute() if !cfg.NonInteractive { @@ -58,7 +58,7 @@ func TestNonInteractiveFlagBindsToCfg(t *testing.T) { func TestNonInteractiveFlagDefaultIsOff(t *testing.T) { cfg := &env.Env{} root := NewRootCmd(cfg, telemetry.New("", true)) - root.SetArgs([]string{"version"}) + root.SetArgs([]string{"--version"}) _ = root.Execute() if cfg.NonInteractive { diff --git a/cmd/root.go b/cmd/root.go index 0efc875..32263a8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -33,7 +33,6 @@ func NewRootCmd(cfg *env.Env, tel *telemetry.Client) *cobra.Command { } root.Version = version.Version() - root.SetVersionTemplate(versionLine() + "\n") root.SilenceErrors = true root.SilenceUsage = true @@ -44,6 +43,7 @@ func NewRootCmd(cfg *env.Env, tel *telemetry.Client) *cobra.Command { root.InitDefaultVersionFlag() root.Flags().Lookup("version").Usage = "Show version" + root.SetVersionTemplate(versionTemplate()) root.AddCommand( newStartCmd(cfg, tel), @@ -52,7 +52,6 @@ func NewRootCmd(cfg *env.Env, tel *telemetry.Client) *cobra.Command { newLogoutCmd(cfg), newLogsCmd(), newConfigCmd(), - newVersionCmd(), newUpdateCmd(cfg), ) diff --git a/cmd/version.go b/cmd/version.go index 344fb3f..ffe6b3b 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -4,21 +4,12 @@ import ( "fmt" "github.com/localstack/lstk/internal/version" - "github.com/spf13/cobra" ) -func newVersionCmd() *cobra.Command { - return &cobra.Command{ - Use: "version", - Short: "Show version", - Long: "Print version information for the lstk binary.", - RunE: func(cmd *cobra.Command, args []string) error { - _, err := fmt.Fprintln(cmd.OutOrStdout(), versionLine()) - return err - }, - } +func versionTemplate() string { + return versionLine() + "\n" } func versionLine() string { - return fmt.Sprintf("lstk %s (%s, %s)", version.Version(), version.Commit(), version.BuildDate()) + return fmt.Sprintf("lstk %s", version.Version()) } diff --git a/cmd/version_test.go b/cmd/version_test.go index b02bfe9..dd028d3 100644 --- a/cmd/version_test.go +++ b/cmd/version_test.go @@ -1,17 +1,33 @@ package cmd -import ( - "strings" - "testing" -) +import "testing" func TestVersionLine(t *testing.T) { got := versionLine() - if !strings.HasPrefix(got, "lstk ") { - t.Fatalf("versionLine() = %q, should start with 'lstk '", got) + if got == "" { + t.Fatal("versionLine() should not be empty") } - if !strings.Contains(got, "(") || !strings.Contains(got, ")") { - t.Fatalf("versionLine() = %q, should contain parentheses with commit and date", got) + if got != "lstk dev" { + t.Fatalf("versionLine() = %q, want %q", got, "lstk dev") + } +} + +func TestVersionFlagsPrintSameOutput(t *testing.T) { + longOut, err := executeWithArgs(t, "--version") + if err != nil { + t.Fatalf("expected no error from --version, got %v", err) + } + + shortOut, err := executeWithArgs(t, "-v") + if err != nil { + t.Fatalf("expected no error from -v, got %v", err) + } + + if longOut != versionTemplate() { + t.Fatalf("--version output = %q, want %q", longOut, versionTemplate()) + } + if shortOut != longOut { + t.Fatalf("-v output = %q, want %q", shortOut, longOut) } } diff --git a/test/integration/update_test.go b/test/integration/update_test.go index 25a87be..3d89933 100644 --- a/test/integration/update_test.go +++ b/test/integration/update_test.go @@ -117,7 +117,7 @@ func TestUpdateBinaryInPlace(t *testing.T) { require.NoError(t, err, "go build failed: %s", string(out)) // Verify it reports the fake version - verCmd := exec.CommandContext(ctx, tmpBinary, "version") + verCmd := exec.CommandContext(ctx, tmpBinary, "--version") verOut, err := verCmd.CombinedOutput() require.NoError(t, err) assert.Contains(t, string(verOut), "0.0.1") @@ -132,7 +132,7 @@ func TestUpdateBinaryInPlace(t *testing.T) { assert.Contains(t, updateStr, "Updated to", "should complete the update") // Verify the binary was actually replaced - verCmd2 := exec.CommandContext(ctx, tmpBinary, "version") + verCmd2 := exec.CommandContext(ctx, tmpBinary, "--version") verOut2, err := verCmd2.CombinedOutput() require.NoError(t, err) assert.NotContains(t, string(verOut2), "0.0.1", "binary should no longer be the old version") @@ -183,7 +183,7 @@ func TestUpdateHomebrew(t *testing.T) { require.NoError(t, err, "go build failed: %s", string(out)) // Verify it reports the fake version - verCmd := exec.CommandContext(ctx, caskBinary, "version") + verCmd := exec.CommandContext(ctx, caskBinary, "--version") verOut, err := verCmd.CombinedOutput() require.NoError(t, err) assert.Contains(t, string(verOut), "0.0.1") From f48457461c3cf35c9b147e97a4f2c8626b3045a7 Mon Sep 17 00:00:00 2001 From: George Tsiolis Date: Thu, 12 Mar 2026 20:03:52 +0200 Subject: [PATCH 2/5] Remove version command from README --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 924936c..281b6bd 100644 --- a/README.md +++ b/README.md @@ -168,8 +168,6 @@ lstk update # Show resolved config file path lstk config path -# Show version info -lstk version ``` ## Reporting bugs From f50c7a01875e54bd7157f0a04ab2a88c742556b5 Mon Sep 17 00:00:00 2001 From: George Tsiolis Date: Thu, 12 Mar 2026 21:01:37 +0200 Subject: [PATCH 3/5] Hide build metadata from public version API --- internal/version/version.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/version/version.go b/internal/version/version.go index 2f705b7..775e4cf 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -8,6 +8,4 @@ var ( buildDate = "unknown" ) -func Version() string { return version } -func Commit() string { return commit } -func BuildDate() string { return buildDate } +func Version() string { return version } From 4c1bbbcd1bde1a8879ceb8edc2c09aa5dc4a26bc Mon Sep 17 00:00:00 2001 From: George Tsiolis Date: Thu, 12 Mar 2026 21:06:09 +0200 Subject: [PATCH 4/5] Keep linker metadata --- internal/version/version.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/version/version.go b/internal/version/version.go index 775e4cf..c2f935a 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -9,3 +9,9 @@ var ( ) func Version() string { return version } + +// Keep linker-populated build metadata embedded for release tooling, +// even though user-facing version output only exposes the version string. +func metadata() (string, string) { + return commit, buildDate +} From be6ed22c07b767146b6f34c493d19d045f26a752 Mon Sep 17 00:00:00 2001 From: George Tsiolis Date: Thu, 12 Mar 2026 21:11:23 +0200 Subject: [PATCH 5/5] Keep linker metadata without exposing it publicly --- internal/version/version.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/internal/version/version.go b/internal/version/version.go index c2f935a..7d7e58b 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -6,12 +6,7 @@ var ( version = "dev" commit = "none" buildDate = "unknown" + _, _ = commit, buildDate ) func Version() string { return version } - -// Keep linker-populated build metadata embedded for release tooling, -// even though user-facing version output only exposes the version string. -func metadata() (string, string) { - return commit, buildDate -}