Skip to content

Implement --non-interactive flag#89

Open
anisaoshafi wants to merge 3 commits intomainfrom
drg-362
Open

Implement --non-interactive flag#89
anisaoshafi wants to merge 3 commits intomainfrom
drg-362

Conversation

@anisaoshafi
Copy link
Contributor

@anisaoshafi anisaoshafi commented Mar 9, 2026

  • adds --non-interactive as a persistent flag on the root command
  • forces plain output (no TUI/spinners) and disables login prompts
  • lstk login --non-interactive fails because it can't open browser
  • lstk start fails when LOCALSTACK_AUTH_TOKEN is not set

@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 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: cbd575f8-4d1f-419f-93ba-b2805e37ae6f

📥 Commits

Reviewing files that changed from the base of the PR and between a7485a2 and 8d99088.

📒 Files selected for processing (8)
  • cmd/login.go
  • cmd/logout.go
  • cmd/non_interactive_test.go
  • cmd/root.go
  • cmd/stop.go
  • internal/env/env.go
  • test/integration/main_test.go
  • test/integration/non_interactive_test.go
🚧 Files skipped from review as they are similar to previous changes (7)
  • cmd/logout.go
  • cmd/root.go
  • cmd/login.go
  • cmd/non_interactive_test.go
  • internal/env/env.go
  • test/integration/non_interactive_test.go
  • cmd/stop.go

📝 Walkthrough

Walkthrough

Adds a persistent --non-interactive flag (bound to Env.NonInteractive), threads the environment config into relevant commands, and switches interactivity checks from ui.IsInteractive() to a new isInteractiveMode(cfg) helper used by login, logout, start/stop flows. New unit and integration tests validate the flag behavior.

Changes

Cohort / File(s) Summary
Flag registration & env
cmd/root.go, internal/env/env.go
Add persistent --non-interactive flag bound to cfg.NonInteractive; add NonInteractive bool field to internal/env.Env.
Command wiring
cmd/stop.go, cmd/root.go
Thread cfg *env.Env into command construction (newStopCmd(cfg)); replace direct ui.IsInteractive() checks with isInteractiveMode(cfg).
Auth commands
cmd/login.go, cmd/logout.go
Replace ui.IsInteractive() usage with isInteractiveMode(cfg) so login/logout respect the new --non-interactive flag.
CLI tests (unit)
cmd/non_interactive_test.go
New unit tests for flag registration, help inclusion, cfg binding, and default state of --non-interactive.
Integration tests & helpers
test/integration/non_interactive_test.go, test/integration/main_test.go
Add integration tests validating non-interactive behavior for login/start; add PTY test helper to exercise interactive flows.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • silv-io
  • carole-lavillonniere
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Implement --non-interactive flag' directly summarizes the main change: adding a new command-line flag to the CLI tool.
Description check ✅ Passed The description is directly related to the changeset, detailing the flag's purpose, behavior, and effects on login and start commands.

✏️ 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 drg-362

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.

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: 2

🧹 Nitpick comments (1)
cmd/non_interactive_test.go (1)

49-50: Assert Execute() succeeds in the binding tests.

These assertions can still pass after an execution failure because flag parsing happens before Execute() returns. Checking the error keeps the tests from masking broken version wiring.

Suggested change
 	root.SetArgs([]string{"--non-interactive", "version"})
-	_ = root.Execute()
+	if err := root.Execute(); err != nil {
+		t.Fatalf("expected no error, got %v", err)
+	}
@@
 	root.SetArgs([]string{"version"})
-	_ = root.Execute()
+	if err := root.Execute(); err != nil {
+		t.Fatalf("expected no error, got %v", err)
+	}

Also applies to: 60-61

🤖 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 49 - 50, The test currently calls
root.SetArgs([...]) and ignores the return from root.Execute(), which can hide
execution failures; update the tests in cmd/non_interactive_test.go (both the
block at lines around the current SetArgs/Execute and the similar block at the
later occurrence) to capture the error returned by root.Execute() and assert it
is nil (e.g., err := root.Execute(); require.NoError(t, err) or equivalent), so
failures in the version command wiring fail the test instead of being masked.
🤖 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/login.go`:
- Around line 20-21: Split the combined guard in cmd/login.go so the
--non-interactive flag produces its own clear error: if cfg.NonInteractive
return an error telling the user that login cannot run with --non-interactive
and to rerun without that flag; otherwise, if !ui.IsInteractive() return the
existing "login requires an interactive terminal" error. Update the conditional
around the login entrypoint (the block currently checking cfg.NonInteractive and
ui.IsInteractive) to check cfg.NonInteractive first, then check
ui.IsInteractive.

In `@test/integration/non_interactive_test.go`:
- Around line 11-40: The tests (TestNonInteractiveFlagBlocksLogin,
TestNonInteractiveFlagFailsWithoutToken,
TestRootNonInteractiveFlagFailsWithoutToken) currently invoke the CLI without a
PTY so ui.IsInteractive() is already false; change them to run the binary inside
a pseudo-terminal using github.com/creack/pty so the flag is the variable under
test. Update each test to spawn the command with pty.Start(cmd) (or add a new
helper like runLstkWithPty that wraps runLstk behavior), stream output with
io.Copy from the PTY to a buffer to capture stderr/stdout, and if needed write
keystrokes to the PTY; assert on the captured output as before to verify
--non-interactive behavior. Ensure the helper preserves environment
modifications (env.Without/With) and returns exit error, stdout/stderr text
similar to the original runLstk contract.

---

Nitpick comments:
In `@cmd/non_interactive_test.go`:
- Around line 49-50: The test currently calls root.SetArgs([...]) and ignores
the return from root.Execute(), which can hide execution failures; update the
tests in cmd/non_interactive_test.go (both the block at lines around the current
SetArgs/Execute and the similar block at the later occurrence) to capture the
error returned by root.Execute() and assert it is nil (e.g., err :=
root.Execute(); require.NoError(t, err) or equivalent), so failures in the
version command wiring fail the test instead of being masked.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro

Run ID: 6e689a3e-ba7d-44dc-93de-bccc75c56a68

📥 Commits

Reviewing files that changed from the base of the PR and between cd3f6b3 and a7485a2.

📒 Files selected for processing (7)
  • cmd/login.go
  • cmd/logout.go
  • cmd/non_interactive_test.go
  • cmd/root.go
  • cmd/stop.go
  • internal/env/env.go
  • test/integration/non_interactive_test.go

Copy link
Member

@silv-io silv-io left a comment

Choose a reason for hiding this comment

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

LGTM!

Only thing that needs fixing IMO is the test not using pty.

@anisaoshafi anisaoshafi marked this pull request as draft March 10, 2026 11:29
@anisaoshafi anisaoshafi force-pushed the drg-362 branch 2 times, most recently from a58b2dc to 16be97e Compare March 10, 2026 12:03
@anisaoshafi anisaoshafi marked this pull request as ready for review March 10, 2026 12:11
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.

3 participants