Skip to content

[scanner] parseFlags accepts --switch=value as 'on' and silently drops flags that name no blank #313

Closed

Description

@hivecommons-hive

Summary

parseFlags (src/flags.ts) has two silent-acceptance gaps on a template run, both contradicting the help text and the strictness #312 just added for positional arguments:

  1. A switch written with a value is treated as "on", whatever the value. --json=false, --cross=0, --status=no, --no-interactive=false all enable the switch. HELP in src/cli.ts says "switches above take no value", yet the value is accepted and ignored.
  2. A flag that names no blank in the template is silently discarded. promptargs review --fiel=main.go (typo) raises nothing; {{file}} falls through to autodetect/default/interactive prompt as though the flag were never given. resolve() only reads flags[v.name] for declared vars; nothing checks the reverse direction.

Reproduction (head 35d615c)

promptargs 'Hi {{name}}' --name=x --json=false
# → "\"Hi x\""  (JSON output; =false enabled it)

promptargs 'Hi {{name}}' --name=x --no-interactive=false </dev/tty
# → non-interactive (any value is truthy)

promptargs 'Review {{file}}' --fiel=main.go --no-interactive
# → "Review " with no error; the typo'd flag vanished

Why

  • src/flags.ts:62-66 — the eq > 0 branch stores flags[name] = value before the SWITCHES check, so a switch never reaches the "takes no value" path.
  • src/cli.ts:118-120 — cross, asJson, statusOnly use 'name' in flags; interactive uses !flags['no-interactive'], truthy for 'false'.
  • src/resolver.ts:121-123 — only vars are iterated; flag names with no matching var are never examined.

Proposed fix

  • In parseFlags, throw UsageError when a SWITCHES member is given =value (Invalid --json: --json takes no value).
  • In src/cli.ts template path, after parseVars, throw UsageError for any flag key that is not a declared variable and not a switch (Unknown flag --fiel: template "review" has no {{fiel}} blank). Only switches and declared blanks are legal on a template run; ui keeps --port.
  • Tests in src/flags.test.ts / src/cli.test.ts; rebuild dist/ (CI dist-sync gate); add changelog.d/fixed-<slug>.md.

Decision taken by hive: reject rather than warn, consistent with #312 (trailing positional arguments are errors, not warnings). Inline templates ('{{x}}' literal) follow the same rule since their blanks are known before resolve.

Refs #271 (reserved switch names — same locus, different gap).

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

Activity

  1. added
    kind/bugCategorizes issue or PR as related to a bug.
    agent/scannerCreated by Hive for agent-filed issue provenance
    on Oct 22, 2026
  2. added
    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
    on Oct 22, 2026
  3. hivecommons-hive commented on Oct 22, 2026

    @hivecommons-hive
    ContributorAuthor

    stage 020-claimed → 010-actionable: actionable

  4. hivecommons-hive commented on Oct 22, 2026

    @hivecommons-hive
    ContributorAuthor

    🔒 Claimed by @mendezr (contributor on hive hosted-available-oke-11-placeholder-r05x). The claim lasts 30m0s without activity and renews while the work continues. Reply /unclaim to release, or /claim to take it over if you outrank the holder.

  5. hivecommons-hive commented on Oct 22, 2026

    @hivecommons-hive
    ContributorAuthor

    Folded finding. This was filed as a separate issue, but 1 open agent-filed issue (plus 5 closed as completed in the last 14 days) already cite src/flags.ts, so it was folded into the oldest of them instead of opening another. Treat this issue as the tracker for that component: prefer one structural fix that covers every folded variant over a PR per variant.

    Review backlog (style): Null-prototype flags map and spread copy go beyond #313's stated scope

    Filed from an out-of-scope finding in the Hive review of PR #314.

    PR: #314 (#314)
    Perspective: style
    Severity: info (P3)
    Evidence: src/flags.ts:65 (

    const flags: Record<string, string> = Object.create(null);
    )
    Finding: Null-prototype flags map and spread copy go beyond #313's stated scope

    The Object.create(null) + { ...flags } change (flags.ts:65, :90) exists so --proto=x is rejected instead of vanishing. It is a reasonable extension of the 'silently dropped flag' class and is covered by src/flags.test.ts:111-118, but #313 did not ask for it; noting for the record only.

    Fingerprint: f3e67a8c41bccf6f2c6729eee4070c3ecf6414af7beb1678d7d906fd222bccfb

    filed by Hive review backlog

  6. hivecommons-hive commented on Oct 22, 2026

    @hivecommons-hive
    ContributorAuthor

    Linked again from the Hive review of PR #314.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/reviewerCreated by Hive for agent-filed issue provenanceagent/scannerCreated by Hive for agent-filed issue provenancehelp wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.hive/claimed-by-scannerkind/bugCategorizes issue or PR as related to a bug.stage/040-covered-by-prAn open PR covers this issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions