Skip to content

Remove version command and simplify version output#107

Open
gtsiolis wants to merge 5 commits intomainfrom
george/des-165
Open

Remove version command and simplify version output#107
gtsiolis wants to merge 5 commits intomainfrom
george/des-165

Conversation

@gtsiolis
Copy link
Member

@gtsiolis gtsiolis commented Mar 12, 2026

This PR simplifies version reporting in lstk and aligns it with common CLI conventions.

  1. Removes the version subcommand
  2. Keeps -v and --version as the supported version entry points
  3. Simplifies version output to a single plain line, lstk 0.4.1 for production and lstk dev for development

The previous setup exposed three different version entry points and printed extra build metadata by default. That added surface area without much user value. This change narrows the interface to the standard flag-based pattern most CLIs use, which is simpler for both humans and automation:

  1. Easier to discover and remember
  2. Less output parsing ambiguity
  3. Cleaner default UX
  4. Better fit for agent-readiness, where deterministic plain output matters more than decorative metadata (PRO-236)
BEFORE AFTER
Screenshot 2026-03-12 at 16 04 50 Screenshot 2026-03-12 at 16 04 38

This will also remove the version.Commit and version.BuildDate. I know uv includes commit and build metadata in a compact format, but for lstk the current output structure adds noise and makes the binary feel more like a development build than a polished release.

For reference:

lstk --version uv --version
Screenshot 2026-03-12 at 16 04 58 Screenshot 2026-03-12 at 16 14 02

@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: e498aa0a-a290-4478-bc26-3f2f8fa1a229

📥 Commits

Reviewing files that changed from the base of the PR and between f50c7a0 and be6ed22.

📒 Files selected for processing (1)
  • internal/version/version.go

📝 Walkthrough

Walkthrough

The PR removes the version subcommand, consolidates version output to the --version flag and a new version template, strips exported commit/build date accessors, updates root command wiring, and adjusts tests/docs to use --version and to assert help/version formatting.

Changes

Cohort / File(s) Summary
Version implementation
cmd/version.go, cmd/version_test.go, internal/version/version.go
Removed newVersionCmd() and exported Commit()/BuildDate(); added versionTemplate() and simplified versionLine() to "lstk ". Tests updated for exact output and added TestVersionFlagsPrintSameOutput.
Root command
cmd/root.go
Set version template via versionTemplate() earlier and removed registration of the version subcommand from root initialization.
CLI tests & help
cmd/help_test.go, cmd/non_interactive_test.go, test/integration/update_test.go
Replaced positional version subcommand uses with the --version flag; added help assertion that help text does not contain \n version pattern.
Docs
README.md
Removed example/mention of the lstk version step from README instructions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • silv-io
  • carole-lavillonniere
  • anisaoshafi
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Remove version command and simplify version output' accurately and concisely summarizes the main changes in the pull request.
Description check ✅ Passed The description clearly explains the PR's objectives, changes, and rationale with before/after examples, directly relating to the changeset modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch george/des-165
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can make CodeRabbit's review stricter and more nitpicky using the `assertive` profile, if that's what you prefer.

Change the reviews.profile setting to assertive to make CodeRabbit's nitpick more issues in your PRs.

@gtsiolis gtsiolis self-assigned this Mar 12, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
cmd/version.go (1)

13-15: Remove the now-dead build metadata plumbing.

versionLine() now only consumes version.Version(), so internal/version.Commit(), internal/version.BuildDate(), and the matching ldflags in .goreleaser.yaml are dead. Cleaning those up in the same change would keep the version model truly single-source and avoid shipping unused metadata in release builds.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/version.go` around lines 13 - 15, versionLine() now only uses
version.Version(), so remove the unused build metadata plumbing: delete
internal/version.Commit() and internal/version.BuildDate() implementations and
any callers, remove the corresponding ldflags from .goreleaser.yaml, and
consolidate the source of truth to version.Version() (leave version.Version()
intact); update any docs/comments referencing Commit/BuildDate to avoid dead
code and ensure releases no longer include those unused fields.
cmd/root.go (1)

48-56: Call out the lstk version removal in release notes or migration docs.

Dropping the subcommand is a CLI breaking change for automation that still invokes lstk version. If the hard removal is intentional, I'd make sure the release notes explicitly point users to lstk --version / lstk -v.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/root.go` around lines 48 - 56, The CLI removed the legacy "lstk version"
subcommand (see root.AddCommand where subcommands like newStartCmd/newStopCmd
are registered), which is a breaking change for users and automation; update the
release notes and migration documentation to explicitly call out removal of
"lstk version", mention the supported alternatives "lstk --version" and "lstk
-v", and provide a short migration note or example command for CI scripts to
replace the old subcommand with the new flag-based usage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/non_interactive_test.go`:
- Around line 47-52: The tests TestNonInteractiveFlagBindsToCfg (and the similar
test at 58-62) currently ignore the error from root.Execute() and then assert on
cfg.NonInteractive; change them to check the returned error first (e.g.,
require.NoError(t, err) or if err != nil { t.Fatalf(...)}), then assert
cfg.NonInteractive so a failing Execute() (such as broken --version handling)
will fail the test instead of producing a false positive; locate root :=
NewRootCmd(...) and the subsequent root.Execute() call and update the test to
capture and assert on the error before inspecting cfg.NonInteractive.

---

Nitpick comments:
In `@cmd/root.go`:
- Around line 48-56: The CLI removed the legacy "lstk version" subcommand (see
root.AddCommand where subcommands like newStartCmd/newStopCmd are registered),
which is a breaking change for users and automation; update the release notes
and migration documentation to explicitly call out removal of "lstk version",
mention the supported alternatives "lstk --version" and "lstk -v", and provide a
short migration note or example command for CI scripts to replace the old
subcommand with the new flag-based usage.

In `@cmd/version.go`:
- Around line 13-15: versionLine() now only uses version.Version(), so remove
the unused build metadata plumbing: delete internal/version.Commit() and
internal/version.BuildDate() implementations and any callers, remove the
corresponding ldflags from .goreleaser.yaml, and consolidate the source of truth
to version.Version() (leave version.Version() intact); update any docs/comments
referencing Commit/BuildDate to avoid dead code and ensure releases no longer
include those unused fields.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 79c82fcd-4c6a-48e0-ac5c-2b1f4a3b9aa5

📥 Commits

Reviewing files that changed from the base of the PR and between ce474bd and 7b4c80b.

📒 Files selected for processing (6)
  • cmd/help_test.go
  • cmd/non_interactive_test.go
  • cmd/root.go
  • cmd/version.go
  • cmd/version_test.go
  • test/integration/update_test.go

Comment on lines 47 to 52
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()

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

Assert that Execute() succeeds in these flag-binding tests.

Both tests can still flip cfg.NonInteractive during flag parsing even if --version is broken, so they may pass while the user-facing path fails. Please check the returned error before asserting on cfg.

Suggested tightening
 func TestNonInteractiveFlagBindsToCfg(t *testing.T) {
 	cfg := &env.Env{}
 	root := NewRootCmd(cfg, telemetry.New("", true))
 	root.SetArgs([]string{"--non-interactive", "--version"})
-	_ = root.Execute()
+	if err := root.Execute(); err != nil {
+		t.Fatalf("expected Execute to succeed, got %v", err)
+	}

 	if !cfg.NonInteractive {
 		t.Fatal("expected cfg.NonInteractive to be true after --non-interactive flag")
 	}
 }
@@
 func TestNonInteractiveFlagDefaultIsOff(t *testing.T) {
 	cfg := &env.Env{}
 	root := NewRootCmd(cfg, telemetry.New("", true))
 	root.SetArgs([]string{"--version"})
-	_ = root.Execute()
+	if err := root.Execute(); err != nil {
+		t.Fatalf("expected Execute to succeed, got %v", err)
+	}

 	if cfg.NonInteractive {
 		t.Fatal("expected cfg.NonInteractive to be false when flag is not set")
 	}
 }

Also applies to: 58-62

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/non_interactive_test.go` around lines 47 - 52, The tests
TestNonInteractiveFlagBindsToCfg (and the similar test at 58-62) currently
ignore the error from root.Execute() and then assert on cfg.NonInteractive;
change them to check the returned error first (e.g., require.NoError(t, err) or
if err != nil { t.Fatalf(...)}), then assert cfg.NonInteractive so a failing
Execute() (such as broken --version handling) will fail the test instead of
producing a false positive; locate root := NewRootCmd(...) and the subsequent
root.Execute() call and update the test to capture and assert on the error
before inspecting cfg.NonInteractive.

@silv-io
Copy link
Member

silv-io commented Mar 12, 2026

The build metadata is needed for goreleaser so it has to stay there

@gtsiolis
Copy link
Member Author

Thanks for taking a look and the insight, @silv-io! Ok then, could we keep the linker-populated build metadata in the binary for Goreleaser and only removed it from the public version output. So --version and -v stay clean, while release builds still embed commit and build date internally.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/root.go`:
- Around line 44-46: The version flag only has the long form; add the -v
shorthand after calling root.InitDefaultVersionFlag() by setting the shorthand
on the existing flag (e.g., use root.Flags().Lookup("version").Shorthand = "v"
and ensure its Usage remains "Show version") so both -v and --version behave
identically; this touches the block using root.InitDefaultVersionFlag(),
root.Flags().Lookup("version").Usage and
root.SetVersionTemplate(versionTemplate()).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 74dc0690-06ee-44bc-9d91-626f9728e33c

📥 Commits

Reviewing files that changed from the base of the PR and between 7b4c80b and f50c7a0.

📒 Files selected for processing (8)
  • README.md
  • cmd/help_test.go
  • cmd/non_interactive_test.go
  • cmd/root.go
  • cmd/version.go
  • cmd/version_test.go
  • internal/version/version.go
  • test/integration/update_test.go
💤 Files with no reviewable changes (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • test/integration/update_test.go
  • cmd/help_test.go
  • cmd/version.go
  • cmd/non_interactive_test.go

Comment on lines 44 to +46
root.InitDefaultVersionFlag()
root.Flags().Lookup("version").Usage = "Show version"
root.SetVersionTemplate(versionTemplate())
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether this repository explicitly wires a -v shorthand for the version flag.
set -euo pipefail

echo "== uses of InitDefaultVersionFlag =="
rg -nP --type=go '\bInitDefaultVersionFlag\s*\('

echo
echo "== explicit version shorthand registrations =="
rg -nP --type=go 'Bool(?:Var)?P\([^)]*"version"\s*,\s*"v"'
rg -nP --type=go 'Lookup\("version"\)\.Shorthand|Shorthand\s*=\s*"v"'

Repository: localstack/lstk

Length of output: 189


🏁 Script executed:

fd -type f -name "*test*.go" cmd/ | head -20

Repository: localstack/lstk

Length of output: 229


🏁 Script executed:

rg -nP --type=go "TestVersionFlagsPrintSameOutput" --context=5

Repository: localstack/lstk

Length of output: 583


🏁 Script executed:

# Also check the git diff or PR changes to understand context
git log --oneline -10

Repository: localstack/lstk

Length of output: 110


🏁 Script executed:

# Check if there are any recent changes to cmd/root.go
git log --oneline cmd/root.go | head -5

Repository: localstack/lstk

Length of output: 110


🏁 Script executed:

cat -n cmd/version_test.go

Repository: localstack/lstk

Length of output: 1034


🏁 Script executed:

# Also check for any calls to root command with -v flag
rg -nP --type=go '"\-v"' cmd/ | head -20

Repository: localstack/lstk

Length of output: 124


🏁 Script executed:

cat -n cmd/root.go | head -80

Repository: localstack/lstk

Length of output: 2695


🏁 Script executed:

# Search for any other version-related wiring in the codebase
rg -nP --type=go "version" cmd/root.go | head -20

Repository: localstack/lstk

Length of output: 303


Wire the -v shorthand for the version flag.

The test at cmd/version_test.go:16 expects both -v and --version flags to produce identical output (lines 17, 22, 30-32), but the current code only registers --version. Cobra's InitDefaultVersionFlag() does not include a shorthand; the -v flag must be explicitly registered.

Suggested fix
-	root.InitDefaultVersionFlag()
-	root.Flags().Lookup("version").Usage = "Show version"
+	root.Flags().BoolP("version", "v", false, "Show version")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/root.go` around lines 44 - 46, The version flag only has the long form;
add the -v shorthand after calling root.InitDefaultVersionFlag() by setting the
shorthand on the existing flag (e.g., use
root.Flags().Lookup("version").Shorthand = "v" and ensure its Usage remains
"Show version") so both -v and --version behave identically; this touches the
block using root.InitDefaultVersionFlag(), root.Flags().Lookup("version").Usage
and root.SetVersionTemplate(versionTemplate()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants