-
Notifications
You must be signed in to change notification settings - Fork 0
Remove version command and simplify version output #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2815a80
f484574
f50c7a0
4c1bbbc
be6ed22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()) | ||
|
Comment on lines
44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 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 -20Repository: localstack/lstk Length of output: 229 🏁 Script executed: rg -nP --type=go "TestVersionFlagsPrintSameOutput" --context=5Repository: localstack/lstk Length of output: 583 🏁 Script executed: # Also check the git diff or PR changes to understand context
git log --oneline -10Repository: 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 -5Repository: localstack/lstk Length of output: 110 🏁 Script executed: cat -n cmd/version_test.goRepository: 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 -20Repository: localstack/lstk Length of output: 124 🏁 Script executed: cat -n cmd/root.go | head -80Repository: 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 -20Repository: localstack/lstk Length of output: 303 Wire the The test at Suggested fix- root.InitDefaultVersionFlag()
- root.Flags().Lookup("version").Usage = "Show version"
+ root.Flags().BoolP("version", "v", false, "Show version")🤖 Prompt for AI Agents |
||
|
|
||
| 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), | ||
| ) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert that
Execute()succeeds in these flag-binding tests.Both tests can still flip
cfg.NonInteractiveduring flag parsing even if--versionis broken, so they may pass while the user-facing path fails. Please check the returned error before asserting oncfg.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