Skip to content

Add --json option and improve CLI output#44

Merged
naheel0 merged 6 commits intomainfrom
index
Mar 4, 2026
Merged

Add --json option and improve CLI output#44
naheel0 merged 6 commits intomainfrom
index

Conversation

@naheel0
Copy link
Member

@naheel0 naheel0 commented Mar 4, 2026

README: add a Quick Start section and document available commands (including explicit analyze command examples).

bin/index.js: use package.json version, introduce a global --json option, and switch to program.opts() to determine JSON mode. Lazily import ora to avoid loading it in JSON mode. Improve child process handling: stream stdout only in pretty mode, avoid printing stderr in JSON mode, handle process killed by signal, return consistent JSON results and exit codes, and simplify spinner/error prints. Replace the previous per-command --json options with the global flag and make analyze an explicit subcommand.

🚀 BΞYTΞFLʘW | Pull Request Protocol

PR Type: (Choose one: feat | fix | refactor | docs | perf)
Issue Link: Fixes #


📝 System Summary

Provide a concise brief of the changes introduced to the stream.

🛠️ Technical Changes

  • Logic change in ...
  • New UI component added: ...
  • Database schema updated: ...

🧪 Quality Assurance (QA)

  • Linting: Code style matches the BeyteFlow grid.
  • Build: npm run build executed without errors.
  • Testing: New logic has been verified and tested.
  • Dark Mode: UI is high-contrast and neon-optimized.

🖼️ Visual Evidence

If this PR affects the UI, drop a screenshot or GIF below:


📡 Developer Authorization

  • I have performed a self-review of my code.
  • My changes generate no new warnings in the console.
  • I have updated the documentation (if applicable).

Authorized by: @Yourusername
Timestamp: {{ date }}


Summary by CodeRabbit

  • New Features

    • Added --json global flag to enable JSON-formatted output across all commands
    • Introduced analyze command for error string analysis with JSON support
  • Documentation

    • Enhanced README with new Quick Start section featuring example commands
    • Added Available Commands reference listing all supported commands
    • Updated usage examples to demonstrate the analyze command workflow

README: add a Quick Start section and document available commands (including explicit `analyze` command examples).

bin/index.js: use package.json version, introduce a global `--json` option, and switch to program.opts() to determine JSON mode. Lazily import ora to avoid loading it in JSON mode. Improve child process handling: stream stdout only in pretty mode, avoid printing stderr in JSON mode, handle process killed by signal, return consistent JSON results and exit codes, and simplify spinner/error prints. Replace the previous per-command `--json` options with the global flag and make `analyze` an explicit subcommand.
@github-actions github-actions bot added documentation Improvements or additions to documentation cli labels Mar 4, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

📝 Walkthrough

Walkthrough

This PR adds global JSON output support via a --json flag to the CLI, restructures the run and analyze command signatures, and updates the README with a Quick Start guide and organized command reference. Documentation examples are aligned to consistently use the analyze command.

Changes

Cohort / File(s) Summary
Documentation
README.md
Added Quick Start section with example commands, new Available Commands subsection listing run/analyze/version commands, and updated all usage examples to use errlens analyze with consistent JSON output formatting.
CLI Implementation
bin/index.js
Added global --json flag for JSON output mode; refactored run and analyze command signatures and moved JSON detection logic to runtime; adjusted spinner, stdout, and stderr handling based on output mode; minor section header rename (PARSE ARGUMENTS → PARSE).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 The CLI hops with newfound grace,
A --json flag shows its face,
Commands dance in structured lines,
Analyze errors, output shines,
Documentation guides the way,
Errors fade in JSON display!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: adding a global --json option and improving CLI output handling with reorganized documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 index

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

🧹 Nitpick comments (2)
bin/index.js (2)

92-92: Avoid implicit return in forEach callback.

The console.log() return value (undefined) is being implicitly returned, which Biome flags. While harmless here, use a block body for clarity.

♻️ Suggested fix
-          matches.forEach((m) => console.log(formatError(m)));
+          matches.forEach((m) => {
+            console.log(formatError(m));
+          });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/index.js` at line 92, The forEach callback currently uses a concise arrow
body that implicitly returns console.log(formatError(m)); change it to a
block-bodied callback to avoid returning undefined: update the
matches.forEach(...) invocation so the callback is written as (m) => {
console.log(formatError(m)); } referencing the existing matches array and
formatError function; no other behavior changes are needed.

137-137: Avoid implicit return in forEach callback.

Same pattern as line 92 - use a block body for the callback.

♻️ Suggested fix
-      matches.forEach((m) => console.log(formatError(m)));
+      matches.forEach((m) => {
+        console.log(formatError(m));
+      });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/index.js` at line 137, Change the implicit-return arrow callback in the
matches.forEach call to use a block-bodied function so the callback is explicit;
replace matches.forEach((m) => console.log(formatError(m))) with a block-bodied
arrow (e.g., matches.forEach((m) => { console.log(formatError(m)); })) to match
the style used elsewhere (see the earlier forEach pattern) and ensure
consistency around the use of formatError in the callback.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bin/index.js`:
- Line 5: The current static CommonJS require of chalk (const chalk =
require("chalk")) will fail because chalk v5+ is ESM-only; replace the static
require with a dynamic import where chalk is needed (similar to how ora is
imported dynamically): inside the async function or action that uses chalk, call
const { default: chalk } = await import("chalk") and use that local chalk
reference; ensure you remove or replace the top-level require("chalk") and place
the dynamic import in the same scope as the existing ora dynamic import so no
top-level await or module type changes are required.

---

Nitpick comments:
In `@bin/index.js`:
- Line 92: The forEach callback currently uses a concise arrow body that
implicitly returns console.log(formatError(m)); change it to a block-bodied
callback to avoid returning undefined: update the matches.forEach(...)
invocation so the callback is written as (m) => { console.log(formatError(m)); }
referencing the existing matches array and formatError function; no other
behavior changes are needed.
- Line 137: Change the implicit-return arrow callback in the matches.forEach
call to use a block-bodied function so the callback is explicit; replace
matches.forEach((m) => console.log(formatError(m))) with a block-bodied arrow
(e.g., matches.forEach((m) => { console.log(formatError(m)); })) to match the
style used elsewhere (see the earlier forEach pattern) and ensure consistency
around the use of formatError in the callback.

ℹ️ Review info
Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c1728e3-d434-406e-9400-dbae95b0f687

📥 Commits

Reviewing files that changed from the base of the PR and between bedb902 and cc20a41.

📒 Files selected for processing (2)
  • README.md
  • bin/index.js

@jaseel0
Copy link
Collaborator

jaseel0 commented Mar 4, 2026

@copilot
Verify each finding against the current code and only fix it if needed.

In @bin/index.js at line 5, The current static CommonJS require of chalk (const
chalk = require("chalk")) will fail because chalk v5+ is ESM-only; replace the
static require with a dynamic import where chalk is needed (similar to how ora
is imported dynamically): inside the async function or action that uses chalk,
call const { default: chalk } = await import("chalk") and use that local chalk
reference; ensure you remove or replace the top-level require("chalk") and place
the dynamic import in the same scope as the existing ora dynamic import so no
top-level await or module type changes are required.

Copy link
Contributor

Copilot AI commented Mar 4, 2026

@jaseel0 I've opened a new pull request, #45, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits March 4, 2026 05:01
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 `@bin/index.js`:
- Around line 104-114: The error handler for child.on("error", (err) => { ... })
must stop the CLI spinner before writing the pretty (non-JSON) error to avoid
overlapping output; update the handler to check for the spinner instance (e.g.,
spinner) and call its stop/clear method (or stopSpinner()) before calling
console.log(chalk.red(...)) while leaving JSON output path unchanged and then
call process.exit(1).

ℹ️ Review info
Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 29a88f00-7dd4-47fc-a784-055ce90e441f

📥 Commits

Reviewing files that changed from the base of the PR and between c005e83 and b7833a6.

📒 Files selected for processing (1)
  • bin/index.js

Comment on lines 104 to 114
child.on("error", (err) => {
const result = { code: 1, count: 0, matches: [] };

if (isJson) {
const result = { code: 1, count: 0, matches: [] };
console.log(JSON.stringify(result, null, 2));
} else {
spinner.fail(chalk.red(`System Error: ${err.message}`));
console.log(chalk.red(`System Error: ${err.message}`));
}

process.exit(1);
});
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

Stop spinner before printing error in pretty mode.

The error handler doesn't stop the spinner before logging the error message. In pretty mode, this can cause garbled output where the spinner animation overlaps with the error text.

🛡️ Proposed fix
     child.on("error", (err) => {
       const result = { code: 1, count: 0, matches: [] };
 
       if (isJson) {
         console.log(JSON.stringify(result, null, 2));
       } else {
+        if (spinner) spinner.stop();
         console.log(chalk.red(`System Error: ${err.message}`));
       }
 
       process.exit(1);
     });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
child.on("error", (err) => {
const result = { code: 1, count: 0, matches: [] };
if (isJson) {
const result = { code: 1, count: 0, matches: [] };
console.log(JSON.stringify(result, null, 2));
} else {
spinner.fail(chalk.red(`System Error: ${err.message}`));
console.log(chalk.red(`System Error: ${err.message}`));
}
process.exit(1);
});
child.on("error", (err) => {
const result = { code: 1, count: 0, matches: [] };
if (isJson) {
console.log(JSON.stringify(result, null, 2));
} else {
if (spinner) spinner.stop();
console.log(chalk.red(`System Error: ${err.message}`));
}
process.exit(1);
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/index.js` around lines 104 - 114, The error handler for child.on("error",
(err) => { ... }) must stop the CLI spinner before writing the pretty (non-JSON)
error to avoid overlapping output; update the handler to check for the spinner
instance (e.g., spinner) and call its stop/clear method (or stopSpinner())
before calling console.log(chalk.red(...)) while leaving JSON output path
unchanged and then call process.exit(1).

@naheel0 naheel0 merged commit 2a205e6 into main Mar 4, 2026
5 checks passed
@naheel0 naheel0 deleted the index branch March 4, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli dependencies documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants