Skip to content

bug: repeated --file flag silently drops all but last value #483

@carlos-alm

Description

@carlos-alm

Summary

When passing --file multiple times (e.g. codegraph complexity --file a.js --file b.js --file c.js), Commander.js silently keeps only the last value. The other files are ignored without any warning, producing unexpectedly empty results.

Reproduction

# Returns results (paginate.js has functions with complexity data):
codegraph complexity --file src/shared/paginate.js -j
# → functions: [printNdjson, paginate, paginateResult]

# Returns empty — Commander only sees the last value (kinds.js has no functions):
codegraph complexity --file src/shared/paginate.js --file src/shared/errors.js --file src/shared/kinds.js -j
# → functions: []

Root cause

All 17 commands that accept --file define it as a single-value option:

['-f, --file <path>', 'Scope to file (partial match)']

Commander.js treats repeated single-value options as "last wins" — no error, no warning. Users naturally expect multiple --file flags to scope across all specified files.

Affected commands

ast, audit, batch, cfg, check, children, complexity, context, dataflow, flow, fn-impact, owners, query, roles, search, sequence, triage, where

Proposed fix

Two options (not mutually exclusive):

  1. Make --file variadic — change to <path...> so Commander collects all values into an array. Update query layers to accept string | string[] and build n.file LIKE ? OR n.file LIKE ? clauses.

  2. Warn on repeated single-value options — detect when Commander overwrites a value and emit a warning. This is harder since Commander doesn't expose a hook for this.

Option 1 is the cleaner fix. The LIKE filter in complexityData (and similar in other query functions) would change from a single AND n.file LIKE ? to AND (n.file LIKE ? OR n.file LIKE ? ...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions