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 | e20a23b370e64c6f09a57b4ddefd6f650e89ba13 (patch) | |
tree | 9a8c05e15b071bc7fd3f78017d76b8ffb4824e32 /qpid/cpp/src/qpidd.cpp | |
parent | a848dc683403f7f2cb26c693b561d3aa70506efb (diff) | |
download | qpid-python-e20a23b370e64c6f09a57b4ddefd6f650e89ba13.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@1388032 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/qpidd.cpp')
-rw-r--r-- | qpid/cpp/src/qpidd.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/qpid/cpp/src/qpidd.cpp b/qpid/cpp/src/qpidd.cpp index b5686c6ab8..920009580c 100644 --- a/qpid/cpp/src/qpidd.cpp +++ b/qpid/cpp/src/qpidd.cpp @@ -41,6 +41,18 @@ int run_broker(int argc, char *argv[], bool hidden) { BootstrapOptions bootOptions(argv[0]); string defaultPath (bootOptions.module.loadDir); + + // --version causes print and exit + if (bootOptions.findArg(argc, argv, "version")) { + cout << "qpidd (" << qpid::product << ") version " + << qpid::version << endl; + return 0; + } + + // --help sets a flag so that its presence is known despite + // subsequent parse problems. + bool helpArgSeen = bootOptions.findArg(argc, argv, "help"); + // Parse only the common, load, and log options to see which // modules need to be loaded. Once the modules are loaded, // the command line will be re-parsed with all of the @@ -51,8 +63,12 @@ int run_broker(int argc, char *argv[], bool hidden) bootOptions.log.sinkOptions->detached(); qpid::log::Logger::instance().configure(bootOptions.log); } catch (const std::exception& e) { + if (helpArgSeen) { + // provide help even when parsing fails + bootOptions.usage(); + } // Couldn't configure logging so write the message direct to stderr. - cerr << "Unexpected error: " << e.what() << endl; + cerr << endl << "Unexpected error: " << e.what() << endl; return 1; } @@ -67,16 +83,20 @@ int run_broker(int argc, char *argv[], bool hidden) } // Parse options - options.reset(new QpiddOptions(argv[0])); - options->parse(argc, argv, options->common.config); + try { + options.reset(new QpiddOptions(argv[0])); + options->parse(argc, argv, options->common.config); + } catch (const std::exception& /*e*/) { + if (helpArgSeen) { + // provide help even when parsing fails + options->usage(); + } + throw; + } // Options that just print information. - if (options->common.help || options->common.version) { - if (options->common.version) - cout << "qpidd (" << qpid::product << ") version " - << qpid::version << endl; - else if (options->common.help) - options->usage(); + if (helpArgSeen) { + options->usage(); return 0; } |