Refaaaacttt00000rr

This commit is contained in:
Your Name
2025-05-04 11:30:57 +12:00
parent 6380ce9178
commit 0e9466365e
11 changed files with 25977 additions and 219 deletions

View File

@ -33,7 +33,7 @@ void print_help() {
std::cout << std::endl;
std::cout << "dropshell ..." << std::endl;
std::cout << " help Show this help message" << std::endl;
std::cout << " init DIR Add DIR as a local server config directory (can add several)" << std::endl;
std::cout << " edit Edit the configuration of dropshell" << std::endl;
if (gConfig().is_config_set()) {
std::cout << " server NAME Show details for specific server" << std::endl;
@ -68,39 +68,6 @@ int die(const std::string & msg) {
return 1;
}
int init(const std::vector<std::string> &args)
{
std::string lcd;
if (args.size() < 3) {
std::cerr << "Error: init command requires a directory argument" << std::endl;
return 1;
}
try {
if (!gConfig().add_local_config_directory(args[2]))
return 1; // error already reported
gConfig().save_config();
std::cout << "Config directory added: " << gConfig().get_local_config_directories().back() << std::endl;
dropshell::create_readme_local_config_dir(gConfig().get_local_config_directories().back());
if (gConfig().get_local_config_directories().size() ==1)
std::cout << "DropShell is now initialised and you can add a server with 'dropshell create-server <server-name>'" << std::endl;
else
{
std::cout << "DropShell will now use all of the following directories for configuration:" << std::endl;
for (const auto& dir : gConfig().get_local_config_directories()) {
std::cout << " " << dir << std::endl;
}
std::cout << "You can edit the config file manually with: dropshell edit" << std::endl;
}
} catch (const std::exception& e) {
std::cerr << "Error in init: " << e.what() << std::endl;
return 1;
}
return 0;
}
struct ServerAndServices {
std::string server_name;
std::vector<LocalServiceInfo> servicelist;
@ -162,32 +129,38 @@ int main(int argc, char* argv[]) {
return 0;
}
if (cmd == "init") {
return init(argvec);
}
if (cmd == "help" || cmd == "-h" || cmd == "--help" || cmd== "h" || cmd=="halp") {
print_help();
return 0;
}
if (cmd == "edit" && argc < 3) {
std::string config_file = localfile::dropshell_env();
std::filesystem::create_directories( get_parent(config_file) );
edit_file(config_file, "Please ensure any directories you have introduced in the config file exist.");
std::string config_file = localfile::dropshell_json();
if (!edit_file(config_file) || !std::filesystem::exists(config_file))
return die("Error: Failed to edit config file.");
gConfig().load_config();
if (!gConfig().is_config_set())
return die("Error: Failed to load and parse edited config file.");
gConfig().save_config();
gConfig().load_config();
std::cout << "Successfully edited config file." << std::endl;
return 0;
}
// ------------------------------------------------------------
// from here we require the config file to be loaded.
if (!gConfig().is_config_set())
return die("Please run 'dropshell init <path>' to initialise the user directory and create a configuration file.");
return die("Please run 'dropshell edit' to set up the dropshell configuration.");
const std::vector<std::string> & local_config_directories = gConfig().get_local_config_directories();
std::cout << "Config directories: ";
for (auto & dir : local_config_directories)
std::cout << "["<< dir << "] ";
std::cout << std::endl;
const std::vector<std::string> & server_definition_paths = gConfig().get_local_server_definition_paths();
if (server_definition_paths.size()>1) { // only show if there are multiple.
std::cout << "Server definition paths: ";
for (auto & dir : server_definition_paths)
std::cout << "["<< dir << "] ";
std::cout << std::endl;
}
if (cmd == "server" || cmd == "servers" || cmd == "list" || cmd == "view")
switch (argc)