[M5] add cargoxx add/remove (linkdb-validated)
This commit is contained in:
@@ -45,6 +45,19 @@ auto run(int argc, char** argv) -> int {
|
||||
|
||||
auto* clean_cmd = app.add_subcommand("clean", "Remove the build/ directory");
|
||||
|
||||
auto* add_cmd = app.add_subcommand(
|
||||
"add", "Add a dependency to Cargoxx.toml (e.g. cargoxx add fmt@10.2)");
|
||||
std::string add_spec;
|
||||
std::string add_components;
|
||||
add_cmd->add_option("spec", add_spec, "Package spec: <name>@<version>")->required();
|
||||
add_cmd->add_option("--components", add_components,
|
||||
"Comma-separated components (e.g. filesystem,system)");
|
||||
|
||||
auto* remove_cmd =
|
||||
app.add_subcommand("remove", "Remove a dependency from Cargoxx.toml");
|
||||
std::string remove_name;
|
||||
remove_cmd->add_option("name", remove_name, "Package name to remove")->required();
|
||||
|
||||
try {
|
||||
app.parse(argc, argv);
|
||||
} catch (const CLI::ParseError& e) {
|
||||
@@ -119,6 +132,49 @@ auto run(int argc, char** argv) -> int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*add_cmd) {
|
||||
std::string name = add_spec;
|
||||
std::string version;
|
||||
if (auto at = add_spec.find('@'); at != std::string::npos) {
|
||||
name = add_spec.substr(0, at);
|
||||
version = add_spec.substr(at + 1);
|
||||
}
|
||||
std::vector<std::string> components;
|
||||
if (!add_components.empty()) {
|
||||
std::size_t pos = 0;
|
||||
while (pos <= add_components.size()) {
|
||||
auto comma = add_components.find(',', pos);
|
||||
auto piece = add_components.substr(
|
||||
pos, comma == std::string::npos ? add_components.size() - pos
|
||||
: comma - pos);
|
||||
if (!piece.empty()) {
|
||||
components.push_back(std::move(piece));
|
||||
}
|
||||
if (comma == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
pos = comma + 1;
|
||||
}
|
||||
}
|
||||
auto r = cmd_add(cwd, name, version, std::move(components));
|
||||
if (!r) {
|
||||
std::cerr << util::format(r.error());
|
||||
return 1;
|
||||
}
|
||||
std::cout << std::format(" Added {} {}\n", name, version);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (*remove_cmd) {
|
||||
auto r = cmd_remove(cwd, remove_name);
|
||||
if (!r) {
|
||||
std::cerr << util::format(r.error());
|
||||
return 1;
|
||||
}
|
||||
std::cout << std::format(" Removed {}\n", remove_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user