Skip to content

fix: make CLI messages name flags that exist and causes users can act on - #77

Merged
Hendrik-code merged 6 commits into
mainfrom
fix/clearer-cli-messages
Oct 19, 2026
Merged

Hendrik-code merged 6 commits into
mainfrom
fix/clearer-cli-messages

Conversation

@Hendrik-code

Copy link
Copy Markdown
Owner

Problem

Hints naming flags that do not exist. All four survived the 2.0 flag rename:

message flag it names flag that exists
Subreg Mask already exists. Set -override_subreg to create it anew -override_subreg --override-semantic / -os
Vert Mask already exists. Set -override_vert to create it anew -override_vert --override-instance / -oi
Centroids already exists, will load instead. Set -override_ctd = True -override_ctd --override-ctd / -oc
-model_instance/-mv resolved to None -model_instance --model-instance / -mi

A user who follows the hint gets error: unrecognized arguments.

--input on an uncompressed NIfTI. .nii is what most converters produce, and SPINEPS cannot read
it (BIDS_FILE keys the file as nii, the pipeline asks for nii.gz). The old code appended the suffix
unconditionally:

$ spineps sample -i scan.nii -ms t2w
FileNotFoundError: -input does not exist or is not a file, got /abs/scan.nii.nii.gz

That names a path the user never typed and says nothing about compression.

Fix

  • All four messages name the real flag and say what loading/overriding will do.
  • --input validation, in order: append .nii.gz only if nothing exists at the path as given (so
    --input sub-01_T2w keeps working), then report a missing folder, then a missing file, then -- for a
    file that is there but is not .nii.gz -- "SPINEPS reads gzipped NIfTI images (.nii.gz), got scan.nii.
    Compress it first, e.g. 'gzip scan.nii'."
  • Removes a dead if dataset == "" branch, unreachable since the path is passed through Path.absolute().
  • process_dataset's logged arguments no longer include the name of the exclusion list itself.

Tests

unit_tests/test_cli_messages.py includes a guard that walks every user-facing string in entrypoint
and seg_run, extracts anything shaped like a flag, and asserts the parser accepts it -- so the next
rename cannot leave a stale hint behind. It catches all four on main, plus the .nii message.

Full suite: 229 passed, ruff clean.

🤖 Generated with Claude Code

Hendrik-code and others added 4 commits October 5, 2026 08:28
Four hints pointed at flags that were renamed (or never existed):

    "Subreg Mask already exists. Set -override_subreg to create it anew"   # --override-semantic/-os
    "Vert Mask already exists. Set -override_vert to create it anew"       # --override-instance/-oi
    "Centroids already exists ... Set -override_ctd = True"                # --override-ctd/-oc
    "-model_instance/-mv resolved to None"                                 # --model-instance/-mi

and `--input` mishandled the two most common mistakes. An uncompressed `scan.nii`, which
SPINEPS cannot read at all, had `.nii.gz` appended unconditionally and then failed with
"-input does not exist or is not a file, got /abs/scan.nii.nii.gz" -- a path the user
never typed. It now says the image must be gzipped and how to fix it, while
`--input sub-01_T2w` (no extension) keeps working because the suffix is only appended
when nothing exists at the given path. A dead `if dataset == ""` branch (unreachable
after `Path.absolute()`) is removed.

Also stops the log-argument filter from logging its own exclusion list.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`--model-{kind}` is assembled at runtime, so the literal `--model` prefix is not a flag.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`--model-{kind}` is assembled at runtime, so `--model` is not a flag the parser has to know.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A hardcoded POSIX path never appears in the message on Windows, where the input is
absolutised to D:\this\path\...

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Hendrik-code
Hendrik-code merged commit d198996 into main Oct 19, 2026
10 checks passed
@Hendrik-code
Hendrik-code deleted the fix/clearer-cli-messages branch October 19, 2026 11:47
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