Skip to content

fix(cli): update add command support id option#20

Merged
fbosch merged 7 commits into
masterfrom
fix/id-parameter
Feb 3, 2026
Merged

fix(cli): update add command support id option#20
fbosch merged 7 commits into
masterfrom
fix/id-parameter

Conversation

@fbosch
Copy link
Copy Markdown
Owner

@fbosch fbosch commented Feb 3, 2026

Summary

Add --id parameter to add command and refactor argument parsing.

Changes

  • Add --id option to associate custom IDs with sources
  • Refactor parseAddEntries to parse-args.ts module
  • Reorganize CLI help text with dedicated "Add options" section
  • Add --verbose flag for debug logging support
  • Streamline CliCommand types with command-specific arguments

Summary by CodeRabbit

  • New Features

    • Added --verbose flag for enhanced debug output
    • Add command supports explicit --id and per-source target-dir options
    • Improved logging and debug traces during git/fetch operations
  • Improvements

    • Warn when include patterns match no files
    • Warn when overwriting existing TOC files
    • Allow subdomains in host validation and support SCP-style SSH URLs

Copilot AI review requested due to automatic review settings February 3, 2026 13:46
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 3, 2026

Warning

Rate limit exceeded

@fbosch has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 31 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Refactors CLI parsing to structured command payloads, adds a --verbose/ui.debug mode, threads logger callbacks through git/fetch flows, decodes/normalizes include patterns, warns on unmatched includes and overwriting TOC.md, and updates tests to cover these behaviors.

Changes

Cohort / File(s) Summary
CLI core & parsing
src/cli/index.ts, src/cli/parse-args.ts, src/cli/types.ts, src/cli/ui.ts
Reworked argument parsing to return a parsed: CliCommand object; runCommand now accepts only parsed command; added AddEntry and ids payloads for add/remove; introduced --verbose, setVerboseMode() and ui.debug(); moved targetDir into AddEntry.
Git fetch & remote resolution
src/git/fetch-source.ts, src/git/resolve-remote.ts
Threaded optional logger?: (msg:string)=>void through fetch/clone/checkout and resolveRemote; replaced archive-based fetch with clone-from-cache + copy; improved SCP-style URL parsing and allowlist logic to permit subdomains.
Materialize & sync behavior
src/materialize.ts, src/sync.ts, src/toc.ts
Added include-pattern normalization (percent-decoding, paren-escaping) and warning when includes match no files; SyncOptions gains verbose flag and conditionally passes logger to downstream ops; warn when overwriting existing TOC.md.
Tests
tests/cli-add.test.js, tests/cli-parse.test.js, tests/resolve-remote.test.js, tests/sync-materialize.test.js, tests/sync-toc.test.js
Added tests for explicit add IDs, --verbose parsing, SCP-style remote and subdomain allowlist, percent-decoded include patterns, and TOC overwrite warning capture.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant Parser
  participant Runner
  participant Sync
  participant Resolver
  participant Fetcher
  participant Materializer
  participant UI

  CLI->>Parser: parse args (includes --verbose)
  Parser->>CLI: parsed: CliCommand
  CLI->>UI: setVerboseMode(parsed.options.verbose)
  CLI->>Runner: runCommand(parsed)
  Runner->>Sync: run(parsed.command, options)
  Sync->>Resolver: resolveRemoteCommit(...)
  Resolver-->>Sync: commit/hash
  Sync->>Fetcher: fetchSource(..., logger?)
  Fetcher-->>Sync: repoDir (from cache or clone)
  Sync->>Materializer: materializeSource(repoDir, includePatterns...)
  Materializer-->>Sync: materialized files / manifest
  UI-->>CLI: debug/warn messages (via logger)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐇 I hop through args and verbose trails,

Logs stitched in git like tiny rails.
Patterns unescaped, TOCs gently told,
Warnings whispered when old files fold,
A rabbit cheers the cleaner code! 🥕

🚥 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 'fix(cli): update add command support id option' clearly summarizes the main change: adding support for the --id option to the add command.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/id-parameter

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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 3, 2026

Open in StackBlitz

npx https://pkg.pr.new/fbosch/docs-cache@20

commit: 613c94b

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds support for custom source IDs via the --id option in the add command, refactors CLI argument parsing into a dedicated module, and adds verbose logging capabilities. The PR also includes several related improvements to error messaging, pattern matching, and host validation.

Changes:

  • Added --id option to allow custom IDs when adding sources, with support for both pre-specified and retroactive ID assignment
  • Refactored argument parsing logic from src/cli/index.ts to src/cli/parse-args.ts with type-safe command-specific argument structures
  • Added --verbose flag with debug logging for git operations and pattern matching warnings
  • Enhanced host allowlist to support subdomains and SCP-style SSH URLs
  • Added percent-decoding support for include patterns and improved glob pattern handling
  • Removed git archive fallback in favor of consistent clone-based fetching

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/sync-toc.test.js Added test for TOC overwrite warning when regenerating existing TOC files
tests/sync-materialize.test.js Added tests for include pattern warnings and percent-encoded pattern handling
tests/resolve-remote.test.js Added tests for subdomain matching in allowHosts and SCP-style SSH URL parsing
tests/cli-parse.test.js Added test for --verbose flag parsing
tests/cli-add.test.js Added tests for --id option with single and multiple sources
src/toc.ts Added warning when overwriting existing TOC.md files
src/sync.ts Integrated verbose logging for resolve and fetch operations
src/materialize.ts Added pattern normalization with percent-decoding, parentheses escaping, and no-match warnings
src/git/resolve-remote.ts Enhanced host parsing for SCP-style SSH and subdomain matching in allowlist
src/git/fetch-source.ts Removed git archive fallback, added verbose logging throughout git operations
src/cli/ui.ts Added debug logging function with verbose mode support
src/cli/types.ts Refactored CliCommand to use command-specific fields instead of generic args array
src/cli/parse-args.ts Moved parseAddEntries from index.ts, added --id parsing, reorganized command definitions
src/cli/index.ts Removed parseAddEntries (moved to parse-args.ts), added verbose mode initialization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/cli/parse-args.ts Outdated
Comment thread src/git/fetch-source.ts Outdated
Copy link
Copy Markdown

@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

🤖 Fix all issues with AI agents
In `@src/git/fetch-source.ts`:
- Around line 50-55: The current execa invocation in fetch-source.ts sets stdio:
"inherit" when options?.logger is present, which sends raw git output to the
terminal but doesn't forward it to the provided logger; change this to use
"pipe" and, if options?.logger is provided, attach listeners to the child
process stdout/stderr and forward their data to options.logger (include command
context using the same [...configs, ...args] string), otherwise keep "pipe"
behavior; update the execa call and any related error/exit handling in the
function that calls execa so stdout/stderr are captured and logged instead of
inheriting the terminal output.

In `@src/materialize.ts`:
- Around line 235-247: The include-pattern warning is being written
unconditionally via ui.line(...) and will corrupt JSON output when --json is
used; modify the materialization flow to accept a json boolean (add a json
parameter to materializeSource and propagate it from the caller) and change the
check around the warning (the block using includePatterns, files, ui.line,
symbols.warn and resolved.sourceId) to only call ui.line when json is false
(i.e., gate the warning behind !json); ensure callers that invoke
materializeSource pass the json flag so JSON mode can suppress this warning.
🧹 Nitpick comments (1)
src/cli/parse-args.ts (1)

36-119: Consider documenting the --id positional binding rules.

The parseAddEntries function handles complex stateful parsing where --id can appear either before or after a repo:

  • add --id myid repo1 → id binds to following repo
  • add repo1 --id myid → id binds to preceding repo

This is flexible but the behavior may not be obvious to users. Consider adding a comment explaining the binding semantics, or documenting it in the help text.

📝 Suggested documentation comment
+/**
+ * Parses add command arguments into AddEntry[].
+ * Supports flexible --id placement:
+ * - `add --id myid repo1` → id binds to the following source
+ * - `add repo1 --id myid` → id binds to the preceding source
+ * - `add --source repo1 --id myid` → id binds to the preceding --source
+ */
 const parseAddEntries = (rawArgs: string[]): AddEntry[] => {

Comment thread src/git/fetch-source.ts Outdated
Comment thread src/materialize.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

@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

🤖 Fix all issues with AI agents
In `@src/cli/parse-args.ts`:
- Around line 88-99: The error text for missing value when handling the arg
variable in the parse-args block that checks for "--target" or "--target-dir"
should mention both option names (or the actual arg used) instead of always
saying "--target expects a value"; update the thrown Error in the branch that
checks !next || next.startsWith("-") so it reports either "`--target` or
`--target-dir` expects a value" or interpolates the actual arg (arg) into the
message; adjust the string thrown in that branch and ensure the change is
applied where entries[lastIndex].targetDir is set in the same switch/if
handling.

Comment thread src/cli/parse-args.ts
@fbosch fbosch merged commit 0b60436 into master Feb 3, 2026
13 checks passed
@fbosch fbosch deleted the fix/id-parameter branch February 3, 2026 14:14
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.

2 participants