Skip to content

Add explain and quiet CLI modes - #25

Merged
JosephMaynard merged 4 commits into
masterfrom
feat/add-explain
Mar 18, 2026
Merged

JosephMaynard merged 4 commits into
masterfrom
feat/add-explain

Conversation

@JosephMaynard

@JosephMaynard JosephMaynard commented Mar 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add dependency-radar explain <package> to print existing scan insights for a single dependency in the terminal
  • add --quiet to suppress scan progress/info output while keeping summaries and policy failures visible
  • update CLI output/docs, including the scan footer URL and README usage examples
  • add regression coverage so the default scan flow continues to behave as before

Testing

  • npx tsc --noEmit
  • npm run test:unit

Summary by CodeRabbit

  • New Features

    • New explain command shows detailed per-package reports (versions, vulnerabilities, licenses, upgrade blockers) and exits non‑zero when a package isn’t found.
    • Added --quiet flag to suppress progress, browser opening, and footer while still printing final summary and failures; supports CI/scripting scenarios.
  • Documentation

    • README expanded with quiet-mode examples, CI usage notes, and explain-command usage and output behavior.
  • Tests

    • Added tests covering explain output, quiet-mode behavior, and related CLI flows.

@coderabbitai

coderabbitai Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 29a3d0e4-f5ff-4053-aa62-29f721a1c0a8

📥 Commits

Reviewing files that changed from the base of the PR and between 23faa32 and b3ebc62.

📒 Files selected for processing (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

📝 Walkthrough

Walkthrough

Adds a new explain command and a --quiet CLI flag, refactors CLI flow to return richer analysis results, introduces explain rendering/filtering utilities, expands tests for explain and quiet behavior, and updates README with usage and CI guidance.

Changes

Cohort / File(s) Summary
Documentation
README.md
Documented --quiet behavior, added "Explain one dependency in the terminal" section, CI/scripting examples, and notes about explain reusing the normal scan pipeline with report writing disabled.
CLI Core & Entrypoint
src/cli.ts, package.json
Added explain command, --quiet flag, new run/dispatch functions (executeAnalysis, runScanCommand, runExplainCommand), progress reporter abstraction, terminal hyperlink support, and richer AnalysisExecutionResult metadata.
Explain Module & Tests
src/explain.ts, src/explain.test.ts
New explain utilities: ExplainAvailability, ExplainRenderContext, findDependenciesByPackageName, formatExplainOutput, version comparison and rendering helpers; tests for matching, multi-version output, offline/unavailable handling.
CLI Tests & Helpers
src/cli.test.ts
Added test helpers (makeTempDir, runCli), temp-dir cleanup, fixture copying, new tests for explain command behavior, quiet-mode suppression semantics, policy-failure visibility, and updated banner/assertions to full dependency-radar URL.

Sequence Diagram(s)

sequenceDiagram
    participant User as User / CLI
    participant CLI as CLI Handler
    participant Analysis as executeAnalysis
    participant Formatter as Output Formatter

    Note over User,Formatter: Scan Command Flow
    User->>CLI: run(['scan'], cwd)
    CLI->>Analysis: executeAnalysis(options)
    Analysis->>Analysis: Run full pipeline (ls, audit, reports)
    Analysis->>Formatter: Generate report artifacts (HTML/JSON)
    Formatter->>CLI: Return AnalysisExecutionResult
    CLI->>User: Print progress, summary, open report
Loading
sequenceDiagram
    participant User as User / CLI
    participant CLI as CLI Handler
    participant Analysis as executeAnalysis
    participant Filter as findDependenciesByPackageName
    participant Formatter as formatExplainOutput

    Note over User,Formatter: Explain Command Flow
    User->>CLI: run(['explain','pkg-name'], cwd)
    CLI->>Analysis: executeAnalysis(options with reports disabled)
    Analysis->>CLI: Return AnalysisExecutionResult
    CLI->>Filter: findDependenciesByPackageName(aggregated, 'pkg-name')
    Filter->>CLI: Return matches (sorted)
    CLI->>Formatter: formatExplainOutput('pkg-name', matches, context)
    Formatter->>CLI: Return formatted text
    CLI->>User: Print explain output (exit non-zero if no matches)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐇 I hopped through code with a tiny grin,

"Explain" now peeks where dependencies begin.
Quiet knocks softly, shushing the race—
leaving summaries neat in their place.
A carrot for tests, and a hop for grace. 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add explain and quiet CLI modes' accurately summarizes the main changes: introduction of two new CLI features (explain command and quiet mode) that are the primary focus of the pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-explain
📝 Coding Plan
  • Generate coding plan for human review comments

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
README.md (1)

288-289: Clarify “same pipeline” scope to avoid confusion with scan-only options.

Since Line 288 references the scan pipeline, consider explicitly noting that explain reuses collectors but suppresses report writing/output generation. This avoids readers inferring identical option/output behavior across commands.

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

In `@README.md` around lines 288 - 289, Update the README sentence about the
explain command to explicitly state its scope: clarify that the explain command
reuses the same scan pipeline collectors (e.g., artifact collectors, metadata
collectors) but suppresses report writing and any output-generation steps, and
that scan-only options which control report formats or storage are not applied;
mention that explain filters the in-memory model to a single package for
terminal output rather than producing the full report.
src/cli.ts (1)

1094-1110: Argument parsing for explain command has a subtle issue with positional argument handling.

The current logic at lines 1108-1110 checks !arg.startsWith("-") to capture the package name, but this happens inside the while loop after the command has been shifted. If a user runs dependency-radar explain --offline lodash, the --offline flag will be processed first, but lodash will only be captured if opts.packageName is still falsy.

However, there's a control flow concern: the else if chain means that once a non-flag argument is encountered for explain, subsequent flags won't be processed correctly if the user places the package name before flags.

Consider validating the argument order or documenting that package name must come immediately after explain.

📝 Suggested documentation clarification in printHelp
 function printHelp(): void {
   console.log(`dependency-radar [scan] [options]
-dependency-radar explain <package-name> [options]
+dependency-radar explain <package-name> [options]
+
+Note: For \`explain\`, <package-name> must be the first argument after the command.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cli.ts` around lines 1094 - 1110, The explain command's positional
package handling (in the args loop using args, command, and opts.packageName)
currently lives inside an else-if chain that prevents subsequent flags from
being processed if a non-flag argument appears first; change the loop so that
when a non-flag is seen and opts.command === "explain" and opts.packageName is
unset you set opts.packageName immediately but do not block further flag
processing (i.e., don't use an else-if that swallows later flag branches) —
either handle the positional case before the flag checks or set opts.packageName
and continue the loop so later iterations still match flag handlers for options
like --offline. Ensure you reference the same variables/operators (args, arg,
command, opts.command, opts.packageName) when applying the fix.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@README.md`:
- Around line 113-114: The README claim that `explain` “does not fetch registry
metadata” is misleading; update the phrasing around the `explain` feature to
state that it reuses the normal local scan model and therefore may trigger
registry lookups in the same situations as `audit`/`outdated` (unless run with
`--offline`), and clarify it still filters results in memory and does not
generate `dependency-radar.html`; reference the `explain`, `audit`, and
`outdated` commands and the `--offline` flag so readers understand network
behavior is dependent on the underlying scan mode rather than guaranteed absent.

---

Nitpick comments:
In `@README.md`:
- Around line 288-289: Update the README sentence about the explain command to
explicitly state its scope: clarify that the explain command reuses the same
scan pipeline collectors (e.g., artifact collectors, metadata collectors) but
suppresses report writing and any output-generation steps, and that scan-only
options which control report formats or storage are not applied; mention that
explain filters the in-memory model to a single package for terminal output
rather than producing the full report.

In `@src/cli.ts`:
- Around line 1094-1110: The explain command's positional package handling (in
the args loop using args, command, and opts.packageName) currently lives inside
an else-if chain that prevents subsequent flags from being processed if a
non-flag argument appears first; change the loop so that when a non-flag is seen
and opts.command === "explain" and opts.packageName is unset you set
opts.packageName immediately but do not block further flag processing (i.e.,
don't use an else-if that swallows later flag branches) — either handle the
positional case before the flag checks or set opts.packageName and continue the
loop so later iterations still match flag handlers for options like --offline.
Ensure you reference the same variables/operators (args, arg, command,
opts.command, opts.packageName) when applying the fix.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 26d49235-25b1-41b8-a837-b37c3c66832d

📥 Commits

Reviewing files that changed from the base of the PR and between 6b47600 and 23faa32.

⛔ Files ignored due to path filters (2)
  • dist/cli.js is excluded by !**/dist/**
  • dist/explain.js is excluded by !**/dist/**
📒 Files selected for processing (5)
  • README.md
  • src/cli.test.ts
  • src/cli.ts
  • src/explain.test.ts
  • src/explain.ts

Comment thread README.md Outdated
@JosephMaynard
JosephMaynard merged commit 5a44957 into master Mar 18, 2026
1 check passed
@JosephMaynard
JosephMaynard deleted the feat/add-explain branch March 18, 2026 16:41
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.

1 participant