1 #include "Configuration.h"
3 namespace remote
{ namespace diku_mcs
{
5 void Configuration::printHelp(po::options_description
& desc
)
7 std::cerr
<< PACKAGE_NAME
<< " (MCH) version " << PACKAGE_VERSION
8 << std::endl
<< std::endl
14 void Configuration::read(int argc
, char **argv
)
16 // command line options
17 po::options_description
cmdline_options("Command line options");
19 cmdline_options
.add_options()
20 ("help", "Print usage help and exit")
21 ("config-help", "Print config file usage help and exit")
23 po::value
<std::string
>()->default_value("/etc/diku_mcs.cfg"),
24 "Path to the configuration file.")
26 po::value
<int>()->default_value(false),
29 // declare all configuration groups
30 po::options_description
config("Configuration options");
34 po::value
<std::string
>(),
35 "Name of the infrastructure database.")
37 po::value
<std::string
>(),
38 "Host name of the infrastructure database server.")
40 po::value
<std::string
>(),
41 "User name for the infrastructure database.")
43 po::value
<std::string
>(),
44 "Password for the infrastructure database.")
45 ("sessionListenerPort",
46 po::value
<unsigned int>()->default_value(10000),
47 "Port number to use when listening for new sessions.")
49 po::value
<unsigned int>()->default_value(10001),
50 "Port number to use when listening for new hosts.")
52 po::value
<std::string
>()->default_value("/var/log/diku_mcs.log"),
53 "Path to the output log file when running as a daemon.")
55 po::value
<std::string
>()->default_value("/var/log/diku_mcs_error.log"),
56 "Path to the error log file when running as a daemon.")
60 store(po::parse_command_line(argc
, argv
, cmdline_options
), vm
);
61 } catch (boost::program_options::error exception
) {
62 std::cerr
<< "Error while parsing command line options: "
63 << exception
.what() << std::endl
<< std::endl
;
64 printHelp(cmdline_options
);
69 printHelp(cmdline_options
);
70 if (vm
.count("config-help"))
73 // get the configuration settings from a file
74 std::ifstream
ifs(Configuration::vm
["config-file"].as
<std::string
>().c_str());
76 store(parse_config_file(ifs
, config
), vm
);
77 } catch (boost::program_options::error exception
) {
78 std::cerr
<< "Error while parsing configuration file: "
79 << exception
.what() << std::endl
<< std::endl
;
85 po::variables_map
Configuration::vm
;