diff --git a/implementations/Crafter.Build-Clang.cpp b/implementations/Crafter.Build-Clang.cpp index 550023e..f93451a 100644 --- a/implementations/Crafter.Build-Clang.cpp +++ b/implementations/Crafter.Build-Clang.cpp @@ -1651,6 +1651,10 @@ Build options: -v, --verbose Verbose progress output. -q, --quiet Suppress progress output. --project= 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