Skip to content

Give source-finder's options to its own parser only - #96

Open
Athanaseus wants to merge 1 commit into
res-cutoutsfrom
t-flag
Open

Athanaseus wants to merge 1 commit into
res-cutoutsfrom
t-flag

Conversation

@Athanaseus

Copy link
Copy Markdown
Owner

Problem

$ aimfast source-finder -sf aegean -r image.fits -t 7
aimfast: error: ambiguous option: -t could match -thresh, -tol, -title, -title-size

Why

argparse classifies every token against the main parser before handing anything to a subcommand. -t isn't a main-parser option, so it's matched by prefix there — and four main options start with -t.

allow_abbrev=False doesn't prevent this: in Python 3.10–3.13 it only disables prefix matching for -- options, not single-dash ones. It's the same mechanism behind the -r / -refpos clash fixed in the dr-refpos PR, so any future option could trigger it again.

Fix

A new parse_args(argv) hands every token after the subcommand to that subcommand's own parser, laid over the main parser's defaults (the rest of main() still reads those). main() uses it.

  • Without a subcommand, parsing is unchanged.
  • Main-parser options placed before the subcommand still apply.
  • Calling get_argparser().parse_args() directly with the subcommand still hits the argparse behaviour; use parse_args().

argparse classifies every token against the main parser before dispatching, and
single-dash options match by prefix there even with allow_abbrev=False. So
source-finder -t matched -thresh, -tol, -title and -title-size and failed as
ambiguous. parse_args() now hands everything after the subcommand to its parser,
over the main parser's defaults.
@Athanaseus
Athanaseus added this pull request to stack #92 September 15, 2026 19:31

This branch has not been deployed

No deployments
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.

1 participant