summaryrefslogtreecommitdiff
path: root/cpp/lib
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2006-12-06 08:11:57 +0000
committerGordon Sim <gsim@apache.org>2006-12-06 08:11:57 +0000
commit905c59a988010c9db7f64ee90f9d0b6e1011f0d0 (patch)
tree60bfef5035aea1284d1d216de2c57ebd8ba9063f /cpp/lib
parent7ece6a3212f401f5ce298e01728f939e670dc4d9 (diff)
downloadqpid-python-905c59a988010c9db7f64ee90f9d0b6e1011f0d0.tar.gz
Patch sumbitted to qpid-dev:
2006-12-05 Jim Meyering <meyering@redhat.com> Improve --help output. Add --version option. * lib/broker/Configuration.cpp: Include <config.h>. (Configuration::Configuration): Use the active voice. Handle --version. (Configuration::usage): Add Usage:... and bug-reporting address. Output short+long options like "-o, --option ...", so that help2man will format them properly. * lib/broker/Configuration.h: (class Configuration) [version, programName]: New members. (parse): Update prototype. (isVersion, setValue): New prototypes. * src/qpidd.cpp: Include <config.h>. (programName): New file-scoped global. (handle_signal, main): Emit diagnostics to stderr. (main): Pass program name to config.parse. (main): Handle new --version option. Also updated ConfigurationTest to use the modified parse() method. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@482958 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/lib')
-rw-r--r--cpp/lib/broker/Configuration.cpp58
-rw-r--r--cpp/lib/broker/Configuration.h6
2 files changed, 42 insertions, 22 deletions
diff --git a/cpp/lib/broker/Configuration.cpp b/cpp/lib/broker/Configuration.cpp
index 8008ea151b..ccc5de7fa9 100644
--- a/cpp/lib/broker/Configuration.cpp
+++ b/cpp/lib/broker/Configuration.cpp
@@ -7,9 +7,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,18 +20,20 @@
*/
#include <Configuration.h>
#include <string.h>
+#include <config.h>
using namespace qpid::broker;
using namespace std;
-Configuration::Configuration() :
+Configuration::Configuration() :
trace('t', "trace", "Print incoming & outgoing frames to the console (default=false)", false),
- port('p', "port", "Sets the port to listen on (default=5672)", 5672),
- workerThreads("worker-threads", "Sets the number of worker threads to use (default=5).", 5),
- maxConnections("max-connections", "Sets the maximum number of connections the broker can accept (default=500).", 500),
- connectionBacklog("connection-backlog", "Sets the connection backlog for the servers socket (default=10)", 10),
- store('s', "store", "Sets the message store module to use (default='' which implies no store)", ""),
- help("help", "Prints usage information", false)
+ port('p', "port", "Set the port to listen on (default=5672)", 5672),
+ workerThreads("worker-threads", "Set the number of worker threads to use (default=5).", 5),
+ maxConnections("max-connections", "Set the maximum number of connections the broker can accept (default=500).", 500),
+ connectionBacklog("connection-backlog", "Set the connection backlog for the servers socket (default=10)", 10),
+ store('s', "store", "Set the message store module to use (default='' which implies no store)", ""),
+ help("help", "Print usage information", false),
+ version("version", "Print version information", false)
{
options.push_back(&trace);
options.push_back(&port);
@@ -40,11 +42,13 @@ Configuration::Configuration() :
options.push_back(&connectionBacklog);
options.push_back(&store);
options.push_back(&help);
+ options.push_back(&version);
}
Configuration::~Configuration(){}
-void Configuration::parse(int argc, char** argv){
+void Configuration::parse(char const *progName, int argc, char** argv){
+ programName = progName;
int position = 1;
while(position < argc){
bool matched(false);
@@ -59,15 +63,25 @@ void Configuration::parse(int argc, char** argv){
}
void Configuration::usage(){
+ std::cout << "Usage: " << programName << " [OPTION]..." << std::endl
+ << "Start the Qpid broker daemon." << std::endl << std::endl
+ << "Options:" << std::endl;
for(op_iterator i = options.begin(); i < options.end(); i++){
(*i)->print(std::cout);
}
+
+ std::cout << std::endl << "Report bugs to <" << PACKAGE_BUGREPORT << ">."
+ << std::endl;
}
bool Configuration::isHelp() const {
return help.getValue();
}
+bool Configuration::isVersion() const {
+ return version.getValue();
+}
+
bool Configuration::isTrace() const {
return trace.getValue();
}
@@ -92,10 +106,10 @@ const std::string& Configuration::getStore() const {
return store.getValue();
}
-Configuration::Option::Option(const char _flag, const string& _name, const string& _desc) :
+Configuration::Option::Option(const char _flag, const string& _name, const string& _desc) :
flag(string("-") + _flag), name("--" +_name), desc(_desc) {}
-Configuration::Option::Option(const string& _name, const string& _desc) :
+Configuration::Option::Option(const string& _name, const string& _desc) :
flag(""), name("--" + _name), desc(_desc) {}
Configuration::Option::~Option(){}
@@ -121,12 +135,14 @@ bool Configuration::Option::parse(int& i, char** argv, int argc){
}
void Configuration::Option::print(ostream& out) const {
- out << " ";
+ out << " ";
if(flag.length() > 0){
- out << flag << " or ";
+ out << flag << ", ";
+ } else {
+ out << " ";
}
out << name;
- if(needsValue()) out << "<value>";
+ if(needsValue()) out << " <value>";
out << std::endl;
out << " " << desc << std::endl;
}
@@ -134,10 +150,10 @@ void Configuration::Option::print(ostream& out) const {
// String Option:
-Configuration::StringOption::StringOption(const char _flag, const string& _name, const string& _desc, const string _value) :
+Configuration::StringOption::StringOption(const char _flag, const string& _name, const string& _desc, const string _value) :
Option(_flag,_name,_desc), defaultValue(_value), value(_value) {}
-Configuration::StringOption::StringOption(const string& _name, const string& _desc, const string _value) :
+Configuration::StringOption::StringOption(const string& _name, const string& _desc, const string _value) :
Option(_name,_desc), defaultValue(_value), value(_value) {}
Configuration::StringOption::~StringOption(){}
@@ -156,10 +172,10 @@ void Configuration::StringOption::setValue(const std::string& _value){
// Int Option:
-Configuration::IntOption::IntOption(const char _flag, const string& _name, const string& _desc, const int _value) :
+Configuration::IntOption::IntOption(const char _flag, const string& _name, const string& _desc, const int _value) :
Option(_flag,_name,_desc), defaultValue(_value), value(_value) {}
-Configuration::IntOption::IntOption(const string& _name, const string& _desc, const int _value) :
+Configuration::IntOption::IntOption(const string& _name, const string& _desc, const int _value) :
Option(_name,_desc), defaultValue(_value), value(_value) {}
Configuration::IntOption::~IntOption(){}
@@ -178,10 +194,10 @@ void Configuration::IntOption::setValue(const std::string& _value){
// Bool Option:
-Configuration::BoolOption::BoolOption(const char _flag, const string& _name, const string& _desc, const bool _value) :
+Configuration::BoolOption::BoolOption(const char _flag, const string& _name, const string& _desc, const bool _value) :
Option(_flag,_name,_desc), defaultValue(_value), value(_value) {}
-Configuration::BoolOption::BoolOption(const string& _name, const string& _desc, const bool _value) :
+Configuration::BoolOption::BoolOption(const string& _name, const string& _desc, const bool _value) :
Option(_name,_desc), defaultValue(_value), value(_value) {}
Configuration::BoolOption::~BoolOption(){}
diff --git a/cpp/lib/broker/Configuration.h b/cpp/lib/broker/Configuration.h
index 1dfc191018..3f2ffd1662 100644
--- a/cpp/lib/broker/Configuration.h
+++ b/cpp/lib/broker/Configuration.h
@@ -97,6 +97,8 @@ namespace qpid {
IntOption connectionBacklog;
StringOption store;
BoolOption help;
+ BoolOption version;
+ char const *programName;
typedef std::vector<Option*>::iterator op_iterator;
std::vector<Option*> options;
@@ -111,9 +113,10 @@ namespace qpid {
Configuration();
~Configuration();
- void parse(int argc, char** argv);
+ void parse(char const*, int argc, char** argv);
bool isHelp() const;
+ bool isVersion() const;
bool isTrace() const;
int getPort() const;
int getWorkerThreads() const;
@@ -122,6 +125,7 @@ namespace qpid {
const std::string& getStore() const;
void setHelp(bool b) { help.setValue(b); }
+ void setVersion(bool b) { version.setValue(b); }
void setTrace(bool b) { trace.setValue(b); }
void setPort(int i) { port.setValue(i); }
void setWorkerThreads(int i) { workerThreads.setValue(i); }