1 /* $Id: ex_libxml2_conf.cpp,v 1.1 2005-10-24 13:31:36 marc Exp $
2 Copyright (c) 2005, Index Data.
10 #include <boost/program_options.hpp>
11 namespace po = boost::program_options;
17 Config(int argc, char **argv)
20 po::options_description generic("Generic options");
22 ("help,h", "produce help message")
23 ("version,v", "version number")
26 po::options_description config("Config options");
28 ("config,c", po::value<std::string>(&m_config)->default_value("ex_libxml2_conf.xml"),
29 "config XML file path (string)")
30 ("duration,d", po::value<int>(&m_duration)->default_value(3),
31 "number of seconds for server to exist (int)")
32 //("commands", po::value< std::vector<std::string> >(),
33 // "listener ports (string)")
36 //po::positional_options_description p;
39 po::options_description cmdline_options;
40 cmdline_options.add(generic).add(config);
45 //po::store(po::command_line_parser(argc, argv).
46 // options(cmdline_options).positional(p).run(), vm);
47 //po::store(po::command_line_parser(argc, argv).
48 // options(cmdline_options).run(), vm);
49 po::store(po::parse_command_line(argc, argv, cmdline_options), vm);
52 catch ( po::invalid_command_line_syntax &e) {
53 std::cerr << "ex_libxml2_conf error: " << e.what() << std::endl;
54 std::cerr << generic << config << std::endl;
57 catch ( po::invalid_option_value &e) {
58 //std::cerr << "ex_libxml2_conf error: " << e.what() << std::endl;
59 std::cerr << "invalid option value" << std::endl;
60 std::cerr << generic << config << std::endl;
63 catch ( po::unknown_option &e) {
64 std::cerr << "ex_libxml2_conf error: " << e.what() << std::endl;
65 std::cerr << generic << config << std::endl;
69 std::cout << "ex_libxml2_conf ";
71 if (vm.count("help")) {
72 std::cout << "--help" << std::endl;
73 std::cout << generic << config << std::endl;
77 if (vm.count("version")) {
78 std::cout << "--version" << std::endl;
82 if (vm.count("duration")) {
83 std::cout << "--duration "
84 << vm["duration"].as<int>() << " ";
86 if (vm.count("config")) {
87 std::cout << "--config "
88 << vm["config"].as<std::string>() << " ";
91 std::cout << std::endl;
93 //if (vm.count("port"))
95 // std::vector<std::string> ports =
96 // vm["port"].as< std::vector<std::string> >();
98 // for (size_t i = 0; i<ports.size(); i++)
99 // std::cout << "port " << i << " " << ports[i] << std::endl;
116 std::string m_config;
118 //xmlDoc * m_conf_doc;
129 int main(int argc, char **argv)
134 Config conf(argc, argv);
136 std::cout << "config " << conf.config() << std::endl;
137 std::cout << "duration " << conf.duration() << std::endl;
142 //std::cerr << "Unknown Exception" << std::endl;
155 * indent-tabs-mode: nil
156 * c-file-style: "stroustrup"
158 * vim: shiftwidth=4 tabstop=8 expandtab