[M1] add cargoxx new

This commit is contained in:
2026-05-08 11:22:34 +00:00
parent 3dc082147a
commit 361b936648
9 changed files with 12555 additions and 11 deletions

48
src/cli/run.cpp Normal file
View File

@@ -0,0 +1,48 @@
module;
#include <CLI11.hpp>
module cargoxx.cli;
import std;
import cargoxx.util;
namespace cargoxx::cli {
auto run(int argc, char** argv) -> int {
CLI::App app{"cargoxx — a Cargo-style project tool for modern C++"};
app.require_subcommand(1);
auto* new_cmd = app.add_subcommand("new", "Create a new cargoxx project");
std::string new_name;
bool new_lib = false;
new_cmd->add_option("name", new_name, "Project name")->required();
new_cmd->add_flag("--lib", new_lib, "Create a library project");
try {
app.parse(argc, argv);
} catch (const CLI::ParseError& e) {
return app.exit(e);
}
if (*new_cmd) {
std::error_code ec;
auto cwd = std::filesystem::current_path(ec);
if (ec) {
std::cerr << std::format("error: cannot determine current working directory: {}\n",
ec.message());
return 1;
}
auto r = cmd_new(new_name, new_lib, cwd);
if (!r) {
std::cerr << util::format(r.error());
return 1;
}
std::cout << std::format(" Created `{}` project\n", new_name);
return 0;
}
return 0;
}
} // namespace cargoxx::cli