Skip to content

fix: correct --force flag logic in update and add --limit validation …#145

Open
emanmunir wants to merge 1 commit intoandrewyng:mainfrom
emanmunir:fix/cli-bugs-force-and-limit
Open

fix: correct --force flag logic in update and add --limit validation …#145
emanmunir wants to merge 1 commit intoandrewyng:mainfrom
emanmunir:fix/cli-bugs-force-and-limit

Conversation

@emanmunir
Copy link

@emanmunir emanmunir commented Mar 18, 2026

Here is the filled-out PR description you can paste into the GitHub PR comment:


What

Two one-line bug fixes in CLI commands:

  1. update.js — Replace opts.force || true with opts.force so the --force flag actually controls cache bypass.
  2. search.js — Add || 20 fallback to parseInt(opts.limit, 10) so a non-numeric --limit value doesn't silently return zero results.

Why

update.js (line 34): opts.force || true is a logical short-circuit that always evaluates to true. This means fetchAllRegistries is called with force = true on every chub update, bypassing the cache unconditionally — the --force flag has no observable effect. With this fix, omitting --force passes undefined, which falls back to the function's default parameter (force = false), restoring cache-aware behavior.

search.js (line 59): parseInt("abc", 10) returns NaN, and Array.slice(0, NaN) returns an empty array. A user passing --limit abc (or any non-numeric string) would silently get zero results with no error message. The || 20 fallback matches the default value already declared in the Commander .option() call.

Testing

  • npm test passes — all 166 passing tests remain passing; the 8 pre-existing failures are Windows path-separator issues unrelated to this change
  • chub build content/ --validate-only succeeds (note: sample-content/ was removed in an earlier commit; see CONTRIBUTING.md references removed sample-content directory #47)
  • Manual testing done:
    • chub update — uses cached registry when fresh (no longer force-refreshes every time)
    • chub update --force — bypasses cache as expected
    • chub search "stripe" --limit abc — falls back to 20 results instead of returning empty

Notes

…in search

Two small bug fixes:

1. update.js: `opts.force || true` always evaluates to true, making
   the --force flag a no-op. `fetchAllRegistries` defaults its parameter
   to false, so passing `opts.force` (undefined when omitted) correctly
   falls back to cache-aware behavior while still honoring --force when
   the user explicitly sets it.

2. search.js: `parseInt(opts.limit, 10)` can produce NaN when a
   non-numeric value is passed (e.g. `--limit abc`). `Array.slice(0, NaN)`
   returns an empty array, silently hiding all results. Added `|| 20`
   fallback to match the declared default.

Made-with: Cursor
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