Skip to content

CLI: support --flag=value syntax in parseFlags#28

Merged
tiagolauer merged 1 commit into
masterfrom
fix-cli-flag-equals-syntax
Jul 19, 2026
Merged

CLI: support --flag=value syntax in parseFlags#28
tiagolauer merged 1 commit into
masterfrom
fix-cli-flag-equals-syntax

Conversation

@tiagolauer

@tiagolauer tiagolauer commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Fixes #25.

What

parseFlags in src/cli/index.ts only understood the spaced --flag value form. --flag=value failed with a misleading error (Missing value for --url=postgres://...), since the whole flag=value fragment was read as the flag name.

Fix

Split each token on its first = before falling back to the spaced-form handling. As a side effect this also lets a value legitimately start with -- when passed via the equals form (--url=--weird-value), since it bypasses the spaced form's startsWith('--') guard entirely.

Test plan

  • npm test (types + runtime) green, 53/53
  • New tests/cli-flags.test.ts: spaced form, equals form, mixed in one call, ---prefixed value via equals, missing-value error still thrown for the spaced form

Summary by CodeRabbit

  • New Features

    • Command-line flags now support both --key value and --key=value formats.
    • Improved error messages identify the specific flag missing a value.
  • Tests

    • Added coverage for mixed flag formats, values beginning with --, and missing-value errors.

parseFlags only understood the spaced --flag value form. The
--flag=value form failed with a misleading error, since the whole
"flag=value" fragment was treated as the flag name and the next argv
entry (or its absence) was blamed for a missing value.

Split each token on its first "=" before falling back to the spaced
form. This also gives an escape hatch for values that legitimately
start with --, which the spaced form's startsWith('--') guard would
otherwise reject.
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d297162d-563d-4672-8634-c6f9f948490c

📥 Commits

Reviewing files that changed from the base of the PR and between b0bff0f and b2014e0.

📒 Files selected for processing (2)
  • src/cli/index.ts
  • tests/cli-flags.test.ts

📝 Walkthrough

Walkthrough

parseFlags is now exported and accepts both --key value and --key=value syntax. Missing-value errors use the parsed flag name, and tests cover mixed forms, dash-prefixed values, and invalid spaced flags.

Changes

CLI flag parsing

Layer / File(s) Summary
Parser export and equals-value handling
src/cli/index.ts
parseFlags is exported, supports --key=value, preserves spaced-value parsing, and reports missing values using the --<key> form.
Parser behavior tests
tests/cli-flags.test.ts
Tests cover spaced and equals forms, mixed usage, values beginning with --, and missing values.

Estimated code review effort: 2 (Simple) | ~10 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-cli-flag-equals-syntax

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.

@tiagolauer
tiagolauer merged commit 56da570 into master Jul 19, 2026
3 of 6 checks passed
@tiagolauer
tiagolauer deleted the fix-cli-flag-equals-syntax branch July 19, 2026 05:20
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.

CLI: support --flag=value syntax in parseFlags

1 participant