diff options
| author | Alan Conway <aconway@apache.org> | 2007-05-01 20:17:25 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2007-05-01 20:17:25 +0000 |
| commit | 9c3ff7ede920804ee07c07bea4152745e55bf330 (patch) | |
| tree | 37706698bea3d494de3eb7864452de60f159ab31 /qpid/cpp/src | |
| parent | bc8f8bfd230a2737c2b5fa6c31222688f9cc6963 (diff) | |
| download | qpid-python-9c3ff7ede920804ee07c07bea4152745e55bf330.tar.gz | |
Moved parseOptions from qipdd to CommonOptions where it can be re-used.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@534226 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src')
| -rw-r--r-- | qpid/cpp/src/qpid/CommonOptions.cpp | 26 | ||||
| -rw-r--r-- | qpid/cpp/src/qpid/CommonOptions.h | 11 | ||||
| -rw-r--r-- | qpid/cpp/src/qpidd.cpp | 22 |
3 files changed, 38 insertions, 21 deletions
diff --git a/qpid/cpp/src/qpid/CommonOptions.cpp b/qpid/cpp/src/qpid/CommonOptions.cpp index d4db3660bd..1b08943088 100644 --- a/qpid/cpp/src/qpid/CommonOptions.cpp +++ b/qpid/cpp/src/qpid/CommonOptions.cpp @@ -17,10 +17,10 @@ */ #include "CommonOptions.h" +#include <fstream> #include <algorithm> namespace qpid { - namespace program_options { char env2optchar(char env) { @@ -52,5 +52,29 @@ void CommonOptions::addTo(po::options_description& desc) ("port,p", optValue(port,"PORT"), "Use PORT for AMQP connections."); } +void parseOptions( + po::options_description& desc, int argc, char** argv, + const std::string& configFile) +{ + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + try { + po::store(po::parse_environment(desc, po::env2option), vm); + } + catch (const po::error& e) { + throw po::error(std::string("parsing environment variables: ") + + e.what()); + } + po::notify(vm); // So we can use the value of config. + try { + std::ifstream conf(configFile.c_str()); + po::store(po::parse_config_file(conf, desc), vm); + } + catch (const po::error& e) { + throw po::error(std::string("parsing config file: ")+ e.what()); + } + po::notify(vm); +} + } // namespace qpid diff --git a/qpid/cpp/src/qpid/CommonOptions.h b/qpid/cpp/src/qpid/CommonOptions.h index beaeb114e6..e166e8f7c9 100644 --- a/qpid/cpp/src/qpid/CommonOptions.h +++ b/qpid/cpp/src/qpid/CommonOptions.h @@ -89,8 +89,19 @@ struct CommonOptions { /** Add members to program_options to be updated */ void addTo(po::options_description&); + }; +/** Convenience function to parse an options_description. + * Parses argc/argv, environment variables and config file. + * Note the filename argument can reference a variable that + * is updated by argc/argv or environment variable parsing. + */ +void parseOptions(po::options_description&, + int argc, char** argv, + const std::string& filename=std::string()); + + } // namespace qpid #endif /*!QPID_COMMONOPTIONS_H*/ diff --git a/qpid/cpp/src/qpidd.cpp b/qpid/cpp/src/qpidd.cpp index 38289ca333..978f9afe4f 100644 --- a/qpid/cpp/src/qpidd.cpp +++ b/qpid/cpp/src/qpidd.cpp @@ -77,26 +77,8 @@ struct QpiddOptions : public Broker::Options } void parse(int argc, char* argv[]) { - po::variables_map vm; - // Earlier sources get precedence. - po::store(po::parse_command_line(argc, argv, desc), vm); - try { - po::store(po::parse_environment(desc, po::env2option), vm); - } - catch (const logic_error& e) { - throw logic_error(string("parsing environment variables: ") - + e.what()); - } - po::notify(vm); // So we can use the value of config. - try { - ifstream conf(config.c_str()); - po::store(po::parse_config_file(conf, desc), vm); - } - catch (const logic_error& e) { - throw logic_error(string("parsing config file: ")+ e.what()); - } - po::notify(vm); - }; + parseOptions(desc, argc, argv, config); + } void usage(ostream& out) const { out << "Usage: qpidd [OPTIONS]" << endl << endl |
