fix(cli): end the options at -- instead of forwarding it
The help has advertised `[options] [-- project-args...]`, but Run never looked for `--`. It fell through to projectArgs as a word of its own, and the words after it were still read as this tool's options and verbs: `crafter-build -- -v` turned verbose output on. In projectArgs `--` changed the project's variant hash, and now that siblings inherit the args, the hash of every sibling down the chain, each building into directories of its own that the project's clean never removes. `--` now ends this tool's options and goes nowhere itself. Every later word is an operand of the verb, as POSIX has it: a project arg for a build, a glob for test, lint and format, the script's name and then its args for run. A glob rather than a project arg after `test` because `crafter-build test -- 'House*'` is how such a filter gets typed; a project arg goes before the `--`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
95896a7ddd
commit
368fd2c527
1 changed files with 22 additions and 1 deletions
|
|
@ -1651,6 +1651,10 @@ Build options:
|
|||
-v, --verbose Verbose progress output.
|
||||
-q, --quiet Suppress progress output.
|
||||
--project=<path> Path to the project file (default: ./project.cpp).
|
||||
-- Ends this tool's options. Every later word is a
|
||||
project arg, even one that looks like an option or
|
||||
a verb; after test, lint or format, a glob; after
|
||||
run, the script's name and then its args.
|
||||
|
||||
Test options (after the `test` subcommand):
|
||||
--list Enumerate matching tests without running them.
|
||||
|
|
@ -1762,6 +1766,9 @@ std::int32_t Crafter::Run(std::int32_t argc, char** argv) {
|
|||
RunLintOptions lintOpts;
|
||||
RunScriptOptions scriptOpts;
|
||||
Progress::Verbosity verbosity = Progress::Verbosity::Default;
|
||||
// Set by `--`: every later word is an operand of the verb, never an
|
||||
// option or a verb of this tool.
|
||||
bool operandsOnly = false;
|
||||
|
||||
for (std::int32_t i = 1; i < argc; ++i) {
|
||||
std::string_view arg = argv[i];
|
||||
|
|
@ -1773,11 +1780,25 @@ std::int32_t Crafter::Run(std::int32_t argc, char** argv) {
|
|||
// variant hash and so the directory the project builds into.
|
||||
if (scriptOpts.named) {
|
||||
scriptOpts.args.emplace_back(arg);
|
||||
} else if (runScript && !arg.starts_with("-")) {
|
||||
} else if (runScript && (operandsOnly || !arg.starts_with("-"))) {
|
||||
// The first word after `run`, even one that is a verb
|
||||
// elsewhere. Options before it keep their usual meaning.
|
||||
scriptOpts.name = arg;
|
||||
scriptOpts.named = true;
|
||||
} else if (operandsOnly) {
|
||||
if (runTests) {
|
||||
testOpts.globs.emplace_back(arg);
|
||||
} else if (runLint || runFormat) {
|
||||
lintOpts.globs.emplace_back(arg);
|
||||
} else {
|
||||
projectArgs.push_back(arg);
|
||||
}
|
||||
} else if (arg == "--") {
|
||||
// Ends this tool's options and is never forwarded itself. It
|
||||
// used to land in projectArgs as a word of its own, giving the
|
||||
// project a variant hash of its own, and every sibling project
|
||||
// that inherits the args one as well.
|
||||
operandsOnly = true;
|
||||
} else if (arg == "--version") {
|
||||
// Answered here, before the project file is looked for, so
|
||||
// it works in any directory and is never forwarded to
|
||||
|
|
|
|||
Loading…
Reference in a new issue