Multiple directories
This commit is contained in:
65
src/main.cpp
65
src/main.cpp
@ -11,7 +11,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <iomanip>
|
||||
namespace dropshell {
|
||||
|
||||
void print_version() {
|
||||
@ -30,7 +30,7 @@ void print_help() {
|
||||
std::cout << std::endl;
|
||||
std::cout << " help Show this help message" << std::endl;
|
||||
std::cout << " version Show version information" << std::endl;
|
||||
std::cout << " init DIR Initialise the local dropshell directory (local config, backups, etc)" << std::endl;
|
||||
std::cout << " init DIR Add a local dropshell config directory (you can add several)" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Server commands:" << std::endl;
|
||||
@ -44,6 +44,11 @@ void print_help() {
|
||||
std::cout << std::endl;
|
||||
std::cout << "Standard commands: install, backup, uninstall, start, stop" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Creation commands: (apply to the first local config directory)"<<std::endl;
|
||||
std::cout << " create-template TEMPLATE" << std::endl;
|
||||
std::cout << " create-server SERVER" << std::endl;
|
||||
std::cout << " create-service SERVER SERVICE" << std::endl;
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
||||
@ -73,27 +78,38 @@ int main(int argc, char* argv[]) {
|
||||
try {
|
||||
dropshell::config *cfg = dropshell::get_global_config();
|
||||
|
||||
// Handle commands
|
||||
std::string cmd;
|
||||
if (argc > 1) {
|
||||
cmd = argv[1];
|
||||
if (argc == 1) {
|
||||
dropshell::print_help();
|
||||
return 0;
|
||||
}
|
||||
std::string cmd = argv[1];
|
||||
|
||||
// silently attempt to load the config file.
|
||||
cfg->load_config();
|
||||
|
||||
// don't load old config if we're initializing
|
||||
if (cmd == "init") {
|
||||
std::string lcd;
|
||||
if (boost::filesystem::exists(dropshell::get_local_dropshell_config_path())) {
|
||||
std::cerr << "DropShell is already initialised in " << dropshell::get_local_dropshell_config_path() << std::endl;
|
||||
std::cerr << "Please manually delete this old config file and re-run the init command." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argc < 3) {
|
||||
std::cerr << "Error: init command requires a directory argument" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
cfg->init_local_config_directory(argv[2]);
|
||||
if (!cfg->add_local_config_directory(argv[2]))
|
||||
return 1; // error already reported
|
||||
cfg->save_config();
|
||||
std::cout << "Config directory added: " << cfg->get_local_config_directories().back() << std::endl;
|
||||
if (cfg->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 : cfg->get_local_config_directories()) {
|
||||
std::cout << " " << dir << std::endl;
|
||||
}
|
||||
std::cout << "You can edit the config file manually at: " << dropshell::get_local_dropshell_config_path() << std::endl;
|
||||
}
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error in init: " << e.what() << std::endl;
|
||||
@ -111,9 +127,6 @@ int main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// silently attempt to load the config file.
|
||||
cfg->load_config();
|
||||
|
||||
// auto completion stuff.
|
||||
std::set<std::string> commands;
|
||||
std::vector<dropshell::ServerInfo> servers = dropshell::get_configured_servers();
|
||||
@ -126,13 +139,11 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
if (cmd == "autocomplete_list_commands") {
|
||||
commands.merge(std::set<std::string>{
|
||||
"help","version"
|
||||
"help","version","init"
|
||||
});
|
||||
if (!boost::filesystem::exists(dropshell::get_local_dropshell_config_path()))
|
||||
commands.insert("init");
|
||||
if (cfg->is_config_set())
|
||||
commands.merge(std::set<std::string>{
|
||||
"servers","templates"
|
||||
"servers","templates","create-service","create-template","create-server"
|
||||
});
|
||||
|
||||
for (const auto& command : commands) {
|
||||
@ -172,9 +183,11 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
std::string lcd;
|
||||
cfg->get_local_config_directory(lcd);
|
||||
std::cout << "Local config path: " << lcd << std::endl;
|
||||
|
||||
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 << std::endl;;
|
||||
// No arguments provided
|
||||
if (argc < 2) {
|
||||
dropshell::print_help();
|
||||
@ -197,6 +210,14 @@ int main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cmd == "create-template") {
|
||||
if (argc < 3) {
|
||||
std::cerr << "Error: create-template requires a template name" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
dropshell::create_template(argv[2]);
|
||||
return 0;
|
||||
}
|
||||
// handle running a command.
|
||||
for (const auto& command : commands) {
|
||||
if (cmd == command) {
|
||||
|
Reference in New Issue
Block a user