CommandLineParameters::CommandLineParameters(int &argc, char **argv)
    : desc_("Allowed options")
    , getHelp_(false)
{
    initDesc();
    parseCommandLineArguments(argc, argv);
}
CommandLineOptions::CommandLineOptions()
    : getHelp_(false)
    , streamerType_(PS_UNKNOWN)
    , width_(0)
    , height_(0)
    , desc_("Allowed options")
{
    initDesc();
}
CommandLineOptions::CommandLineOptions(int &argc, char **argv)
    : getHelp_(false)
    , streamerType_(PS_UNKNOWN)
    , width_(0)
    , height_(0)
    , desc_("Allowed options")
{
    initDesc();
    parseCommandLineArguments(argc, argv);
}
示例#4
0
void Config::init(int argc, char* argv[])
{
    boost::filesystem::path programPath = argv[0];
#if BOOST_VERSION > 104200
    programName = programPath.filename().string();
#else
    programName = programPath.filename();
#endif

    boost::filesystem::path defaultConfig("etc/" + programName + ".conf");
    desc.add_options()
        ("help,h", "show this help and exit.")
        ("config,c", boost::program_options::value<boost::filesystem::path>()->default_value(defaultConfig),
            ("config file, default " + defaultConfig.string() + ".").c_str())
        ("no-config-file", boost::program_options::bool_switch()->default_value(false),
            "force do not load options from config file, default false.");
    initDesc();

    try
    {
        boost::program_options::command_line_parser parser(argc, argv);
        parser.options(desc).allow_unregistered().style(boost::program_options::command_line_style::unix_style);
        boost::program_options::store(parser.run(), options);
    }
    catch (const std::exception& e)
    {
        CS_DIE(e.what() << CS_LINESEP << desc);
    }
    boost::program_options::notify(options);

    if (options.count("help"))
    {
        std::cout << desc << std::endl;
        std::exit(EXIT_SUCCESS);
    }
    else
    {
        bool noConfigFile = options["no-config-file"].as<bool>();
        if (!noConfigFile)
        {
            load(options["config"].as<boost::filesystem::path>());
        }
    }
}