Working on restore command.

This commit is contained in:
Your Name 2025-04-26 18:38:10 +12:00
parent 977e878eff
commit b07e3830de
6 changed files with 14 additions and 12 deletions

View File

@ -75,6 +75,7 @@ fi
# Configure with CMake
print_status "Configuring with CMake..."
cmake .. -DCMAKE_BUILD_TYPE=Debug
#cmake .. -DCMAKE_BUILD_TYPE=Release
# Build the project
print_status "Building project..."

View File

@ -67,18 +67,17 @@ void dropshell::autocomplete(const std::vector<std::string> &args)
std::string service_name = args[4];
if (cmd=="restore")
{
std::set<std::string> backups;
std::vector<dropshell::ServerInfo> servers = dropshell::get_configured_servers();
for (auto server : servers)
backups.merge(dropshell::list_backups(server.name, service_name));
std::set<std::string> backups = dropshell::list_backups(service_name);
for (auto backup : backups)
std::cout << backup << std::endl;
return;
}
return; // no more autocompletion possible - don't know what the argument is for.
}
return;
// args>5 - no more autocompletion possible - don't know what the argument is for.
return; // catch-all.
}
void dropshell::autocomplete_list_commands()

View File

@ -60,7 +60,7 @@ void config::save_config()
envmanager config_env(config_path);
config_env.set_variable("local.config.directories", multi2string(mLocalConfigPaths));
config_env.set_variable("local.backup.path", mLocalBackupPath);
config_env.set_variable("local.backup.directory", mLocalBackupPath);
config_env.save();
}

View File

@ -110,7 +110,7 @@ int main(int argc, char* argv[]) {
const std::vector<std::string> & local_config_directories = cfg->get_local_config_directories();
std::cout << "Config directories: ";
for (auto & dir : local_config_directories)
std::cout << "["<< dir << "] " << std::endl;
std::cout << "["<< dir << "] ";
std::cout << std::endl;
if (cmd == "server" || cmd == "servers" || cmd == "view" || cmd == "views" || cmd == "v")

View File

@ -111,11 +111,11 @@ std::set<std::string> get_used_commands(const std::string &server_name, const st
return commands;
}
std::set<std::string> list_backups(const std::string &server_name, const std::string &service_name)
std::set<std::string> list_backups(const std::string &service_name)
{
std::set<std::string> backups;
if (server_name.empty() || service_name.empty())
if (service_name.empty())
return backups;
std::string backups_dir = get_local_backup_path();
@ -126,9 +126,11 @@ std::set<std::string> list_backups(const std::string &server_name, const std::st
for (const auto& entry : fs::directory_iterator(backups_dir)) {
if (fs::is_regular_file(entry) && entry.path().extension() == ".tgz")
if (entry.path().filename().string().find(service_name) != std::string::npos)
{
backups.insert(entry.path().filename().string());
}
}
}
return backups;
}

View File

@ -18,8 +18,8 @@ namespace dropshell {
ServiceInfo get_service_info(const std::string& server_name, const std::string& service_name);
std::set<std::string> get_used_commands(const std::string& server_name, const std::string& service_name);
// list all backups for a given server and service
std::set<std::string> list_backups(const std::string& server_name, const std::string& service_name);
// list all backups for a given service (across all servers)
std::set<std::string> list_backups(const std::string& service_name);
bool create_service(const std::string& server_name, const std::string& template_name, const std::string& service_name);
} // namespace dropshell