Commit Graph
4 Commits
Author SHA1 Message Date
Hamza ea39c914d2 cli: a missing value stops the line before any export, help wins as a value, and every subcommand's usage lists its options 2026-11-04 13:22:23 +05:00
Hamza 8d17aa1100 test(cli): show that --nope reached the file system, not the parser
The assertion was that the complaint names `--nope`, which a parser rejecting
unknown options would do just as well -- so it did not pin the thing the test is
named for (noted in review).

`validate-pdf --nope` and `validate-pdf nope.pdf` are now compared with the name
taken out, so the shape of the failure has to be the one an ordinary missing path
gets. That holds the behaviour without asserting the operating system's wording
for a missing file, which an earlier round of review rightly took out of here.

Review suggested asserting the JSON report instead. There is none to assert:
`validate-pdf --nope` fails at `std::fs::read`, before any check runs, and
writes nothing to stdout -- which `failed` already requires.

Controlled by adding `o if o.starts_with("--") => return Err(...)` to
`validate_pdf`:

    left:  "designcraft-cli: unknown option <name>\n"
    right: "designcraft-cli: <name>: No such file or directory (os error 2)\n"

The old assertion passes against that left-hand side, since it names `--nope`.
2026-11-02 16:02:59 +05:00
Hamza 2b0d8a4c10 test(cli): don't assert the operating system's wording for a missing file
Review caught a test that cannot pass on Windows: it asserted the error for
`validate-pdf --nope` contains "No such file", which is the unix phrasing.
Windows says "The system cannot find the file specified", so the assertion
failed there even when the command refused the path correctly -- the same
mistake as the `\\?\C:\` one on #1909, and in a test whose point is to run
everywhere.

It asserts the error names the path; `failed()` already checks the exit code
and the stream. The companion check that a `<sub> --help` run did not open a
file now looks for either operating system's wording, so it catches that on
Windows too rather than only on unix.
2026-10-29 13:53:11 +05:00
Hamza b5196b933d test(cli): pin what the argument parser does today (photocraft#7071)
The argument surface had no tests of its own, so the three bugs #7071 lists
could come back without anything noticing. These pin what the parser does:
help in all three spellings, an unknown command, the version, `<sub> --help`
for every subcommand, the options that take a value, the repeatable flags, a
flag that takes no value leaving the next token alone, and a missing value
naming its option.

Carries the review fix: asking for help about a command nobody has is still
an unknown command. usage_for fell back to the whole usage block when it
described no such subcommand, so `bogus --help` printed it on stdout and
exited 0, skipping the failure the test beside it asserts. It answers None
instead -- the usage block names every subcommand, so no second list can
drift from the match that dispatches them.

Rebased onto the post-split main, on top of the rebased #1478. The CLI's
tests live under tests/it/ now, so args.rs went there and is registered in
tests/it/main.rs.

One case needed updating rather than porting: this pinned that an automation
root given twice was an error. Upstream has since made the roots repeatable
(`...` in the usage), so every use adds a folder. The test now pins that --
which is what "what the parser does today" means -- and says so, rather than
holding the parser to behaviour it has deliberately left behind.
2026-10-28 18:36:37 +05:00