diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2015-03-29 00:06:35 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2015-03-29 00:06:35 +0300 |
commit | 42646fc776ff938a4440af5d1cc7be41160a3dbb (patch) | |
tree | fb50bf44186f150ec651015e1ca3dea25ac2fd48 /server/src/main.cpp | |
parent | 264fee4fb3b5ad1c4682a9f233ef781318f74cc8 (diff) |
work in progress
Diffstat (limited to 'server/src/main.cpp')
-rw-r--r-- | server/src/main.cpp | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/server/src/main.cpp b/server/src/main.cpp index 08fe5b7..e8b4e2c 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -18,13 +18,13 @@ */ #include <boost/program_options.hpp> -#include <boost/property_tree/ptree.hpp> -#include <boost/property_tree/info_parser.hpp> #include <boost/filesystem.hpp> #include <iostream> -#include <api_module_metadata_storage.h> -#include <modules_handler.h> +#include "api_module_metadata_storage.h" +#include "modules_handler.h" +#include "utilities.h" +#include "main.h" core_api *module_api = nullptr; @@ -32,9 +32,10 @@ core_api *module_api = nullptr; modules_handler *modules = nullptr; namespace bpo = boost::program_options; -namespace bpt = boost::property_tree; -bpt::ptree config; + + +runtime_config_s runtime_config; @@ -42,19 +43,20 @@ int main(int argc, char *argv[]) { bpo::options_description desc("Available commands and options"); desc.add_options() - ("help", "this message") - ("daemon", "fork to background") - ("config", bpo::value<std::string>(), "use specified config file instead of \"~/.config/udm/udm.conf\"") - ("list-modules", "list all installed modules") + ("help,h", "this message") + ("daemon,d", "fork to background (must be combined with \"--run\", does nothing alone)") + ("config,c", bpo::value<std::string>(), "use specified config file instead of \"~/.config/udm/udm.conf\"") + ("list-modules", "list all installed modules (you can set verbosity level, accepted values from 0 to 1, default = 0)") + ("verbosity,v", bpo::value<short>()->default_value(0), "set global verbosity level") ("run", "start UDM server") ; bool daemon = false, run = false; - std::string config_path = "~/.config/udm/udm.conf"; + std::string config_path = "~/.config/udm/udm.conf", parsed_config_path; try{ bpo::variables_map vm; - bpo::store(bpo::parse_command_line(argc, argv, desc), vm); + bpo::store(bpo::command_line_parser(argc, argv).options(desc).style(bpo::command_line_style::unix_style | bpo::command_line_style::allow_long_disguise).run(), vm); bpo::notify(vm); //load config first, as it may be needed for other commands @@ -62,15 +64,16 @@ int main(int argc, char *argv[]) config_path = vm["config"].as<std::string>(); { - std::string tmp_path = config_path, home = getenv("HOME"); - for(std::string::size_type p1 = tmp_path.find("~"); p1 != std::string::npos; p1 = tmp_path.find("~", p1)) - tmp_path.replace(p1, 1, home); - if(boost::filesystem::exists(tmp_path) && boost::filesystem::is_regular(tmp_path)) - bpt::read_info(tmp_path, config); //TODO: finish this + parsed_config_path = replace_home_var(config_path); + if(boost::filesystem::exists(parsed_config_path) && boost::filesystem::is_regular(parsed_config_path)) + bpt::read_info(parsed_config_path, runtime_config.config_file); //TODO: finish this else std::cerr<<"failed to load config: \"" + config_path + "\", file does not exists or is not regular file\n"; } - + if(vm.count("verbosity")) + { + runtime_config.verbosity = vm["verbosity"].as<short>(); + } if(vm.count("help")) { @@ -88,6 +91,7 @@ int main(int argc, char *argv[]) if(!modules) modules = new modules_handler; std::cout<<modules->list_modules(); + bpt::write_info(parsed_config_path, runtime_config.config_file); //save config on exit return 0; } if(vm.count("run")) @@ -112,10 +116,14 @@ int main(int argc, char *argv[]) { //TODO: fork here } + //TODO: run here } - //module_api must be created first std::cerr<<"error: no command specified"<<std::endl; std::cout<<desc<<std::endl; + bpt::write_info(parsed_config_path, runtime_config.config_file); //save config on exit + + + return 0; } |