diff options
| author | Charles E. Rolke <chug@apache.org> | 2012-09-20 13:48:40 +0000 |
|---|---|---|
| committer | Charles E. Rolke <chug@apache.org> | 2012-09-20 13:48:40 +0000 |
| commit | 2392999ac1d0d3d44c0f28204026ca99fc18cae0 (patch) | |
| tree | 88762c78e34dd5121e9046d954c24373a1918798 /cpp/src/qpid/Options.cpp | |
| parent | c3739c9b10547219943030009f601f330bb9a7c2 (diff) | |
| download | qpid-python-2392999ac1d0d3d44c0f28204026ca99fc18cae0.tar.gz | |
QPID-3500 C++ qpidd broker --help should work despite parse errors
This patch finds and processes --version before anything else.
Then it finds --help before fully parsing command line options.
In the event of a parse error, help usage may be shown as requested.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1388032 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/Options.cpp')
| -rw-r--r-- | cpp/src/qpid/Options.cpp | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/cpp/src/qpid/Options.cpp b/cpp/src/qpid/Options.cpp index 35787aa8f3..9813dda697 100644 --- a/cpp/src/qpid/Options.cpp +++ b/cpp/src/qpid/Options.cpp @@ -41,13 +41,13 @@ struct EnvOptMapper { return desc->long_name().size() == env.size() && std::equal(env.begin(), env.end(), desc->long_name().begin(), &matchChar); } - + static bool matchCase(const string& env, boost::shared_ptr<po::option_description> desc) { return env == desc->long_name(); } - + EnvOptMapper(const Options& o) : opts(o) {} - + string operator()(const string& envVar) { static const std::string prefix("QPID_"); if (envVar.substr(0, prefix.size()) == prefix) { @@ -75,7 +75,7 @@ struct EnvOptMapper { string configFileLine (string& line) { - + if ( isComment ( line ) ) return string(); @@ -85,7 +85,7 @@ struct EnvOptMapper { string key = line.substr (0, pos); #if (BOOST_VERSION >= 103300) typedef const std::vector< boost::shared_ptr<po::option_description> > OptDescs; - OptDescs::const_iterator i = + OptDescs::const_iterator i = find_if(opts.options().begin(), opts.options().end(), boost::bind(matchCase, key, _1)); if (i != opts.options().end()) return string (line) + "\n"; @@ -109,8 +109,8 @@ std::string prettyArg(const std::string& name, const std::string& value) { return value.empty() ? name+" " : name+" ("+value+") "; } -Options::Options(const string& name) : - po::options_description(name) +Options::Options(const string& name) : + po::options_description(name) { } @@ -197,5 +197,33 @@ CommonOptions::CommonOptions(const string& name, const string& configfile, const } + +bool Options::findArg(int argc, char const* const* argv, const std::string& theArg) +{ + const string parsing("command line options"); + bool result(false); + try { + if (argc > 0 && argv != 0) { + po::command_line_parser clp = po::command_line_parser(argc, const_cast<char**>(argv)). + options(*this).allow_unregistered(); + po::parsed_options opts = clp.run(); + + for (std::vector< po::basic_option<char> >::iterator + i = opts.options.begin(); i != opts.options.end(); i++) { + if (theArg.compare(i->string_key) == 0) { + result = true; + break; + } + } + } + return result; + } + catch (const std::exception& e) { + ostringstream msg; + msg << "Error in " << parsing << ": " << e.what() << endl; + throw Exception(msg.str()); + } +} + } // namespace qpid |
