| 367 | } |
| 368 | |
| 369 | int ConfigCommand::Remove(const std::string& inputPath, const std::string& outputPath, |
| 370 | const std::vector<std::string>& paths, bool forceOverwrite, bool ignoreMissing) |
| 371 | { |
| 372 | ParamFile cfg; |
| 373 | if (!ParseConfig(cfg, inputPath)) |
| 374 | { |
| 375 | std::cerr << "Error: failed to parse config: " << inputPath << std::endl; |
| 376 | return 1; |
| 377 | } |
| 378 | |
| 379 | if (forceOverwrite) |
| 380 | { |
| 381 | cfg.SetAccessModeForAll(PADefault); |
| 382 | } |
| 383 | |
| 384 | for (const std::string& path : paths) |
| 385 | { |
| 386 | std::vector<std::string> parts = SplitConfigPath(path); |
| 387 | if (parts.empty()) |
| 388 | { |
| 389 | std::cerr << "Error: empty path" << std::endl; |
| 390 | return 1; |
| 391 | } |
| 392 | |
| 393 | ParamClass* parent = &cfg; |
| 394 | std::string pathSoFar; |
| 395 | for (size_t i = 0; i + 1 < parts.size(); ++i) |
| 396 | { |
| 397 | const std::string& part = parts[i]; |
| 398 | pathSoFar += (pathSoFar.empty() ? "" : " >> ") + part; |
| 399 | ParamEntry* entry = parent->FindEntryNoInheritance(part.c_str()); |
| 400 | if (!entry) |
| 401 | { |
| 402 | if (ignoreMissing) |
| 403 | { |
| 404 | std::cerr << "Missing: " << pathSoFar << std::endl; |
| 405 | parent = nullptr; |
| 406 | break; |
| 407 | } |
| 408 | std::cerr << "Error: not found: " << pathSoFar << std::endl; |
| 409 | return 1; |
| 410 | } |
| 411 | parent = entry->GetClassInterface(); |
| 412 | if (!parent) |
| 413 | { |
| 414 | std::cerr << "Error: not a class: " << pathSoFar << std::endl; |
| 415 | return 1; |
| 416 | } |
| 417 | } |
| 418 | if (!parent) |
| 419 | { |
| 420 | continue; |
| 421 | } |
| 422 | |
| 423 | const std::string& leaf = parts.back(); |
| 424 | if (!parent->FindEntryNoInheritance(leaf.c_str())) |
| 425 | { |
| 426 | if (ignoreMissing) |
nothing calls this directly
no test coverage detected