From 52c4eed8c6a4d88999482c129486fef3c6ce90a5 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Wed, 29 Apr 2026 04:00:07 +0200 Subject: [PATCH] help command --- implementations/Crafter.Build-Clang.cpp | 60 ++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/implementations/Crafter.Build-Clang.cpp b/implementations/Crafter.Build-Clang.cpp index 80248c1..501cc30 100644 --- a/implementations/Crafter.Build-Clang.cpp +++ b/implementations/Crafter.Build-Clang.cpp @@ -852,8 +852,63 @@ void Crafter::EnableWasiBrowserRuntime(Configuration& cfg) { cfg.files.push_back(htmlPath); } +static void PrintHelp(std::string_view argv0) { + std::println( +R"(Usage: + {0} [options] [-- project-args...] Build the project in the current directory + {0} test [test-options] [globs...] Build and run the project's tests + {0} help | -h | --help Show this help + +Loads ./project.cpp (override with --project=), compiles it to a shared +object, and invokes its CrafterBuildProject() to obtain a Configuration that +drives the build. Outputs land at bin/--/, intermediates +at build/--/. + +Build options: + -r Run the produced executable after a successful build + (host targets only; libraries cannot be run). + -v, --verbose Verbose progress output. + -q, --quiet Suppress progress output. + --project= Path to the project file (default: ./project.cpp). + +Test options (after the `test` subcommand): + --list Enumerate matching tests without running them. + --jobs= Parallel job count (default: hardware_concurrency). + --timeout= Per-test timeout override. + --runner= Override the test runner for this run. Specs: + local + cmd: (e.g. cmd:wine) + ssh:[:] + sshwin:[:] + wsl[:] + --target= Filter to tests whose cfg.target matches; this is + also forwarded to project-args so per-target tests + build for that triple. Default: host triple. + One or more name globs to filter tests (e.g. 'Unit*'). + +Project args: + Any flag not consumed above is forwarded verbatim to CrafterBuildProject as + part of its `args` span. Project-specific flags (e.g. --target=, custom + feature toggles) live there. + +Environment: + CRAFTER_BUILD_MARCH Override -march (default: native). + CRAFTER_BUILD_MTUNE Override -mtune (default: native). + CRAFTER_BUILD_RUNNER_ Default test runner for a target triple. + Replace '-' and '.' with '_' in the + triple. CLI --runner= overrides this. + CRAFTER_MINGW_DIR Override mingw-w64 sysroot auto-detect. + LIBCXX_DIR Windows libc++ install (MSVC ABI builds). + +Exit status: + 0 success / all non-skipped tests passed + 1 build failure or one or more tests failed +)", argv0); +} + int Crafter::Run(int argc, char** argv) { try { + std::string_view argv0 = argc > 0 ? argv[0] : "crafter-build"; fs::path projectFile = "./project.cpp"; std::vector projectArgs; projectArgs.reserve(argc); @@ -865,7 +920,10 @@ int Crafter::Run(int argc, char** argv) { for (int i = 1; i < argc; ++i) { std::string_view arg = argv[i]; - if (arg == "test") { + if (arg == "-h" || arg == "--help" || (!runTests && arg == "help")) { + PrintHelp(argv0); + return 0; + } else if (arg == "test") { runTests = true; } else if (arg == "-r") { runAfterBuild = true;