Skip to content

Commit

Permalink
Extracted a new private method with configuration file parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
xvitaly committed Oct 6, 2024
1 parent 8288b3b commit f6b376b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/app/application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,7 @@ int Application::ExecuteEnv() const

int Application::ExecuteConfig(const std::string& ConfigFile) const
{
if (!std::filesystem::exists(ConfigFile)) throw std::invalid_argument("Configuration file does not exist!");
std::ifstream ConfigFileFs(ConfigFile);
boost::program_options::store(boost::program_options::parse_config_file(ConfigFileFs, *ConfigOptions), *Config);
Config -> notify();
ConfigFileFs.close();
ParseConfigFile(ConfigFile);

bool Result = true;
const std::vector<std::pair<std::string, std::function<void(const std::string&)>>> Handlers
Expand Down Expand Up @@ -358,6 +354,15 @@ void Application::ParseCmdLine(int argc, char** argv)
CmdLine -> notify();
}

void Application::ParseConfigFile(const std::string& ConfigFile) const
{
if (!std::filesystem::exists(ConfigFile)) throw std::invalid_argument("Configuration file does not exist!");
std::ifstream ConfigFileFs(ConfigFile);
boost::program_options::store(boost::program_options::parse_config_file(ConfigFileFs, *ConfigOptions), *Config);
Config -> notify();
ConfigFileFs.close();
}

Application::Application(int argc, char** argv)
{
CheckIfRunningBySuperUser();
Expand Down
5 changes: 5 additions & 0 deletions src/app/application/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class Application
*/
void ParseCmdLine(int, char**);

/**
* Reads and parses the specified configuration file.
*/
void ParseConfigFile(const std::string&) const;

/**
* Checks of current application is running with super-user
* privileges.
Expand Down

0 comments on commit f6b376b

Please sign in to comment.