X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/e7ccd2b51d13d9900fb3e841c13562e57448b279..479b8853c2ab18c98926a9369a03888021e9b986:/projects/sgconf/main.cpp diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index 0715b7b1..3413dbd9 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -25,6 +25,7 @@ #include "users.h" #include "services.h" #include "corps.h" +#include "info.h" #include "api_action.h" #include "options.h" @@ -72,7 +73,7 @@ template class FUNC1_ADAPTER : public std::unary_function { public: - FUNC1_ADAPTER(R (*func)(A)) : m_func(func) {} + explicit FUNC1_ADAPTER(R (*func)(A)) : m_func(func) {} const R operator()(A arg) const { return (m_func)(arg); } private: R (*m_func)(A); @@ -120,7 +121,7 @@ return CONST_METHOD1_ADAPTER(func, obj); void Version(const std::string & self) { -std::cout << self << ", version: 2.0.0-alpha.\n"; +std::cout << self << ", version: 2.0.0.\n"; } void ReadUserConfigFile(SGCONF::OPTION_BLOCK & block) @@ -159,12 +160,10 @@ class CONFIG_ACTION : public ACTION m_description(paramDescription) {} - virtual ACTION * Clone() const { return new CONFIG_ACTION(*this); } - - virtual std::string ParamDescription() const { return m_description; } - virtual std::string DefaultDescription() const { return ""; } - virtual OPTION_BLOCK & Suboptions() { return m_suboptions; } - virtual PARSER_STATE Parse(int argc, char ** argv, void * /*data*/); + std::string ParamDescription() const override { return m_description; } + std::string DefaultDescription() const override { return ""; } + OPTION_BLOCK & Suboptions() override { return m_suboptions; } + PARSER_STATE Parse(int argc, char ** argv, void * /*data*/) override; private: SGCONF::CONFIG & m_config; @@ -226,11 +225,10 @@ else } } -inline -CONFIG_ACTION * MakeParamAction(SGCONF::CONFIG & config, - const std::string & paramDescription) +std::unique_ptr MakeParamAction(SGCONF::CONFIG & config, + const std::string & paramDescription) { -return new CONFIG_ACTION(config, paramDescription); +return std::make_unique(config, paramDescription); } } // namespace SGCONF @@ -251,10 +249,15 @@ blocks.Add("General options") SGCONF::OPTION_BLOCK & block = blocks.Add("Connection options") .Add("s", "server", SGCONF::MakeParamAction(config.server, std::string("localhost"), "
"), "\t\thost to connect") .Add("p", "port", SGCONF::MakeParamAction(config.port, uint16_t(5555), ""), "\t\tport to connect") + .Add("local-address", SGCONF::MakeParamAction(config.localAddress, std::string(""), "
"), "\tlocal address to bind") + .Add("local-port", SGCONF::MakeParamAction(config.localPort, uint16_t(0), ""), "\t\tlocal port to bind") .Add("u", "username", SGCONF::MakeParamAction(config.userName, std::string("admin"), ""), "\tadministrative login") .Add("w", "userpass", SGCONF::MakeParamAction(config.userPass, ""), "\tpassword for the administrative login") .Add("a", "address", SGCONF::MakeParamAction(config, ""), "connection params as a single string in format: :@:"); +blocks.Add("Debug options") + .Add("show-config", SGCONF::MakeParamAction(config.showConfig), "\tshow config and exit"); SGCONF::AppendXMLOptionBlock(commands, blocks); +SGCONF::AppendServerInfoBlock(commands, blocks); SGCONF::AppendAdminsOptionBlock(commands, blocks); SGCONF::AppendTariffsOptionBlock(commands, blocks); SGCONF::AppendUsersOptionBlock(commands, blocks); @@ -300,7 +303,11 @@ else config = configOverride; -std::cerr << "Config: " << config.Serialize() << std::endl; +if (!config.showConfig.empty() && config.showConfig.data()) + { + std::cout << config.Serialize() << std::endl; + return 0; + } return commands.Execute(config) ? 0 : -1; } catch (const std::exception& ex)