[M4] add cargoxx run/test/clean

This commit is contained in:
2026-05-10 00:12:25 +00:00
parent f6e8699a72
commit 0a398d1c31
10 changed files with 349 additions and 0 deletions

View File

@@ -30,6 +30,21 @@ auto run(int argc, char** argv) -> int {
build_cmd->add_option("--target", build_target,
"Build a specific target (passed to cmake --build)");
auto* run_cmd = app.add_subcommand("run", "Build and run a binary target");
bool run_release = false;
std::string run_bin;
std::vector<std::string> run_args;
run_cmd->add_flag("--release", run_release, "Run the release profile");
run_cmd->add_option("--bin", run_bin, "Binary target to run");
run_cmd->add_option("args", run_args, "Arguments passed to the binary")
->expected(0, -1);
auto* test_cmd = app.add_subcommand("test", "Build and run all test targets via ctest");
bool test_release = false;
test_cmd->add_flag("--release", test_release, "Test the release profile");
auto* clean_cmd = app.add_subcommand("clean", "Remove the build/ directory");
try {
app.parse(argc, argv);
} catch (const CLI::ParseError& e) {
@@ -72,6 +87,38 @@ auto run(int argc, char** argv) -> int {
return 0;
}
if (*run_cmd) {
std::optional<std::string> bin;
if (!run_bin.empty()) {
bin = run_bin;
}
auto r = cmd_run(cwd, run_release, bin, run_args);
if (!r) {
std::cerr << util::format(r.error());
return 1;
}
return *r;
}
if (*test_cmd) {
auto r = cmd_test(cwd, test_release);
if (!r) {
std::cerr << util::format(r.error());
return 1;
}
return *r;
}
if (*clean_cmd) {
auto r = cmd_clean(cwd);
if (!r) {
std::cerr << util::format(r.error());
return 1;
}
std::cout << " Cleaned build/\n";
return 0;
}
return 0;
}