39 lines
1.3 KiB
C++
39 lines
1.3 KiB
C++
#include "tool.hpp"
|
|
#include <CLI11.hpp>
|
|
|
|
bool processDuplicates(DatabaseManager &db) {
|
|
spdlog::info("=== Checking for duplicate addresses ===");
|
|
bool found_address_duplicates = db.checkDuplicateAddresses();
|
|
if (found_address_duplicates) {
|
|
spdlog::error("Found duplicate addresses in the database!");
|
|
} else {
|
|
spdlog::info("No duplicate addresses found in the database.");
|
|
}
|
|
|
|
spdlog::info("=== Checking for duplicate names ===");
|
|
bool found_name_duplicates = db.checkDuplicateNames();
|
|
if (found_name_duplicates) {
|
|
spdlog::error("Found duplicate names in the database!");
|
|
} else {
|
|
spdlog::info("No duplicate names found in the database.");
|
|
}
|
|
|
|
return !found_address_duplicates && !found_name_duplicates;
|
|
}
|
|
|
|
void register_cmd_verify(CLI::App &app) {
|
|
auto cmd = app.add_subcommand("verify", "Verify the database");
|
|
|
|
cmd->final_callback([]() {
|
|
auto &options = Options::get();
|
|
DatabaseManager db(options.db_path);
|
|
// For duplicates mode, we only check the database, no file processing
|
|
spdlog::info("=== Checking database for duplicates ===");
|
|
bool has_duplicates = !processDuplicates(db);
|
|
spdlog::info("=== Summary ===");
|
|
spdlog::info("Mode: {}", options.mode);
|
|
spdlog::info("Database: {}", options.db_path);
|
|
return has_duplicates ? 1 : 0; // Return 1 if duplicates found, 0 if none
|
|
});
|
|
}
|