fix: suppress spinner output when --json or --silent flag is passed#7982
fix: suppress spinner output when --json or --silent flag is passed#7982DavidWells merged 2 commits intomainfrom
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughRuntime suppression logic was added to the spinner module to conditionally disable spinner output based on command-line arguments (--json, --silent). A Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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. Comment |
📊 Benchmark resultsComparing with df4d195
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/lib/spinner.ts (1)
3-10: Avoid freezing CLI flags at import time.Line [3] snapshots
process.argvonce. If argv is changed after module import (common in tests/programmatic usage), suppression can drift. Prefer reading argv insideshouldSuppressOutput().♻️ Proposed tweak
-const argv = process.argv.slice(2) - -const shouldSuppressOutput = () => argv.includes('--json') || argv.includes('--silent') +const shouldSuppressOutput = () => { + const argv = process.argv.slice(2) + return argv.includes('--json') || argv.includes('--silent') +}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib/spinner.ts` around lines 3 - 10, The module currently snapshots process.argv into the top-level const argv which freezes CLI flags at import time; remove the top-level argv constant and modify shouldSuppressOutput() to call process.argv.slice(2) inside the function and check .includes('--json') || .includes('--silent') so flags are read each time; keep DOTS_SPINNER unchanged and only update shouldSuppressOutput (and remove references to the removed argv symbol).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/lib/spinner.ts`:
- Around line 3-10: The module currently snapshots process.argv into the
top-level const argv which freezes CLI flags at import time; remove the
top-level argv constant and modify shouldSuppressOutput() to call
process.argv.slice(2) inside the function and check .includes('--json') ||
.includes('--silent') so flags are read each time; keep DOTS_SPINNER unchanged
and only update shouldSuppressOutput (and remove references to the removed argv
symbol).
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/lib/spinner.ts
|
nice! |
Summary
--jsonor--silentis passed,startSpinnernow returns a no-op spinner that satisfies theSpinnerinterface but writes nothinglog()incommand-helpers.ts, which already no-ops on--jsonand--silentProblem
We hit this in CI where a script captures CLI output with
2>&1(merging stderr into stdout) and pipes it tojq:Even though
nanospinnerwrites to stderr by default, the2>&1pulls spinner frames (⠋ Creating agent task...) into the captured output.jqthen sees the spinner text before the JSON and fails to parse.While the script could avoid
2>&1, when--jsonis passed the CLI should produce machine-friendly output only — no spinners, no decorative text, regardless of which stream they target.Approach
Rather than adding
if (!options.json)guards at every spinner call site, the suppression is handled centrally instartSpinner. When--jsonor--silentis detected inprocess.argv, it returns a no-op object implementing the fullSpinnerinterface. This means:.stop(),.success(),.error()calls work as beforelog()already handles--json/--silentgloballyTest plan
netlify agents:create "test" --json --agent claudeoutputs clean JSON with no spinner text on stderrnetlify agents:create "test" --json --agent claude 2>&1 | jq -r '.id'parses successfully--json) still shows spinners as beforenpm run typecheckpasses