Skip to content

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

Description

@tiagolauer

What

parseFlags in src/cli/index.ts only understands the two-token form --url <value>. The single-token form most CLIs also accept fails with a message that reads like a different problem:

owlsql generate --url=postgres://localhost/db
Error: Missing value for --url=postgres://localhost/db

The parser takes everything after -- as the flag name (url=postgres://localhost/db), looks at the next argv entry for a value, finds none, and throws. The error names a flag that doesn't exist and never hints at the actual issue.

A related edge in the same loop: any value that legitimately starts with -- is rejected by the value.startsWith('--') guard, so there's no way to pass such a value at all.

Fix idea

Split on the first = before the name/value handling:

const eq = name.indexOf('=');
if (eq !== -1) {
  flags.set(name.slice(0, eq), name.slice(eq + 1));
  continue;
}

That also gives users an escape hatch for values starting with --, which makes the startsWith('--') guard on the two-token form safe to keep as-is.

Acceptance

  • --url=..., --out=..., --dialect=..., --schema=... all work and mix freely with the spaced form.
  • --url --weird-value still errors clearly in the spaced form, while --url=--weird-value passes it through.
  • A couple of cases in a small unit test for parseFlags (may need exporting it or extracting it for testability, same pattern as the map*Type functions).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions