Skip to content

Python options before algorithm - #3428

Merged
Lestropie merged 3 commits into
devfrom
python_options_before_algorithm
Aug 5, 2026
Merged

Python options before algorithm#3428
Lestropie merged 3 commits into
devfrom
python_options_before_algorithm

Conversation

@Lestropie

Copy link
Copy Markdown
Member

An isolated cherry-picked change from a broader interrogation of the software CLI. From onset, for those Python commands that involve an algorithm selection, any command-line options specified before the algorithm selector could be silently dropped. This fixes that behaviour so that if a user pushes such a (non-recommended) usage, it will either fail to parse, or the command-line option will be propagated through to the sub-parser and therefore achieve the intended modulation of behaviour.

A custom `_AlgorithmSelectAction` subclass of `argparse._SubParsersAction`
is registered on every `Parser` instance. The default implementation parsed
algorithm-specific arguments into a fresh namespace and then copied it over
the master namespace, erasing values of any options set before the algorithm
name. The replacement parses those arguments directly into the existing
namespace with the algorithm parser's defaults temporarily suppressed, then
applies any remaining defaults only to attributes not already set. Documentation
for affected commands is updated to state that options may appear either before
or after the algorithm name, and regression tests are added for both `5ttgen`
and `dwi2response`.

Prompt:
> For Python commands where specific algorithms are invoked via subparsers, any command-line options specified before the subparser name are silently dropped. Investigate potential ways to preclude this behaviour. Consider ensuring that options specified before the algorithm name are suitably propagated to the sub-parser, or that they are parsed by the main parser and then merged with the content of the sub-parser, or detecting the presence of such options and issuing a warning to the user, or any other potential solutions. Investigate online for accepted best practise in use of the argparse package in this context.
>
> Worktree safe for modification; implement proposal for user review.

Generated-by: Claude Opus 4.8 <noreply@anthropic.com>
With recent changes, it is no longer the case that any command-line options specified before the algorithm selector will be silently dropped. It is however not true that any command-line option can be placed anywhere on the command-line: while a member of the standard option group specified before the algorithm selector will be appropriately propagated through to the subparser, any algorithm-specific options will not, and will instead be treated as an unrecognised algorithm selection. Help text is therefore refined to say that command-line options *should* be placed after the algorithm name.
@Lestropie Lestropie self-assigned this Aug 4, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

clang-tidy review says "All clean, LGTM! 👍"

@Lestropie
Lestropie merged commit 9996398 into dev Aug 5, 2026
7 checks passed
@Lestropie
Lestropie deleted the python_options_before_algorithm branch August 5, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant