Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/cli.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -2120,8 +2120,12 @@ int run(int argc, char** argv) {
auto parsed = app.parse(trimmed_argc, trimmed_argp);
if (!parsed) {
// `--help` / `--version` come back as a non-error "failure": the
// parser handled them and printed. Nothing to add, nothing to report.
if (!parsed.error().is_error()) return 0;
// parser handled them and printed. Nothing to add; `help <command>`
// is a command of the surface and is recorded as one.
if (!parsed.error().is_error()) {
mcpp::cli::record_answered(app, parsed.error(), trimmed_argc, trimmed_argp);
return 0;
}
return usage_error(parsed.error(), std::span(trimmed_argp + 1, trimmed_argp + trimmed_argc));
}
// `--agent-skill-doc` is answered here, after the parse and before any
Expand Down
13 changes: 13 additions & 0 deletions src/cli/cmd_surface.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ void record_invocation(const mcpplibs::cmdline::App& app, const mcpplibs::cmdlin
// out of it, `--protocol-version` answers before it -- so the parsed record never holds them.
void record_global_flags(const mcpplibs::cmdline::App& app, int argc, char** argv);

// A help the parser answered, recorded as used: `help <command>...` is a command of the surface
// that the parser answers before any action runs, so the parsed record never holds it.
void record_answered(const mcpplibs::cmdline::App& app, const mcpplibs::cmdline::ParseError& answered,
int argc, char** argv);

} // namespace mcpp::cli

module :private;
Expand Down Expand Up @@ -160,4 +165,12 @@ void record_global_flags(const cl::App& app, int argc, char** argv) {
}
}

void record_answered(const cl::App& app, const cl::ParseError& answered, int argc, char** argv) {
if (std::getenv(std::string(sf::kRecordEnv).c_str()) == nullptr) return;
// The parser reads `help` as a command only as the first word, as it is read here.
if (answered.kind != cl::ParseError::help || argc < 2 || std::string_view(argv[1]) != "help") return;
const Node root = cl::snapshot(app);
if (find_sub(root, "help") != nullptr) sf::exercised(sf::kCommand, "help");
}

} // namespace mcpp::cli
10 changes: 7 additions & 3 deletions tests/e2e/actions/generated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ int main() {
s::project app{tmp / "app", {{"mcpp.toml", "[package]\nname = \"app\"\nversion = \"0.1.0\"\n[dependencies]\nproto = { path = \"../proto\" }\n"},
{"src/main.cpp", "#include <cstdio>\nimport proto;\nint main() { std::printf(\"ANSWER=%d\\n\", proto_answer()); }\n"}}};
expect(fatal(e2e::succeeded(app.mcpp({"build"})))) << "a dependency whose action generates its only header did not build";
// The graph is read as the build that compiled the package wrote it. A later command that
// does not replay the graph plans again, finds the package's units in the home's cache the
// build filled, and stages them: its graph has no compile edge of the package (CI,
// 2026-12-06: `mcpp run` planned again in a home other programs of the run write to).
const auto nj = ninja_file(app.at("target"));
expect(fatal(nj.has_value())) << "no build.ninja";
const auto ninja = s::read_file(*nj);
expect(eq(s::last_line(app.mcpp({"run"}).out), std::string{"ANSWER=42"})) << "expected ANSWER=42 from the generated header";
// A path dependency's build program runs into the home's output directory (SPEC-004 §9
// item 18), else into the project's.
Expand All @@ -196,9 +203,6 @@ int main() {
expect(fatal(hdr.has_value())) << "no proto_generated.h anywhere";
expect(fatal(fs::file_size(*hdr) > 0)) << hdr->string() << " is empty — the placeholder, not the generator's output";
expect(e2e::contains(s::read_file(*hdr), "PROTO_ANSWER")) << hdr->string() << " is not what gen.sh writes";
const auto nj = ninja_file(app.at("target"));
expect(fatal(nj.has_value())) << "no build.ninja";
const auto ninja = s::read_file(*nj);
std::smatch m;
const bool any = std::regex_search(ninja, m, std::regex{R"((^|\n)build (mcpp-actions-[^ ]*proto[^ ]*) : phony)"});
expect(fatal(any)) << "no action phony was emitted for the dependency";
Expand Down
Loading