qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r532491 - in /incubator/qpid/trunk/qpid/cpp/src: qpid/CommonOptions.cpp qpid/CommonOptions.h qpidd.cpp
Date Wed, 25 Apr 2007 21:26:54 GMT
Author: aconway
Date: Wed Apr 25 14:26:53 2007
New Revision: 532491

URL: http://svn.apache.org/viewvc?view=rev&rev=532491
Log:
Added environment variables as a source of Qpid configuration.
Option "foo-bar" will be read from env. QPID_FOO_BAR if
not specified on command line.

Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h
    incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp?view=diff&rev=532491&r1=532490&r2=532491
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp Wed Apr 25 14:26:53 2007
@@ -17,8 +17,28 @@
  */
 
 #include "CommonOptions.h"
+#include <algorithm>
 
 namespace qpid {
+
+namespace program_options {
+
+char env2optchar(char env) {
+    return (env=='_') ? '-' : tolower(env);
+}
+    
+const std::string envPrefix("QPID_");
+
+std::string env2option(const std::string& env) {
+    if (env.find(envPrefix) ==0) {
+        std::string opt = env.substr(envPrefix.size());
+        std::transform(opt.begin(), opt.end(), opt.begin(), env2optchar);
+        return opt;
+    }
+    return std::string();
+} 
+
+} // namespace program_options
 
 const int CommonOptions::DEFAULT_PORT=5672;
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h?view=diff&rev=532491&r1=532490&r2=532491
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h Wed Apr 25 14:26:53 2007
@@ -62,6 +62,11 @@
     return new OptionValue<T>(value, argName);
 }
 
+/** Environment-to-option name mapping.
+ * Maps env variable "QPID_SOME_VAR" to option "some-var"
+ */
+std::string env2option(const std::string& env);
+
 /**
  * Like boost::program_options::bool_switch but takes reference, not pointer.
  */

Modified: incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp?view=diff&rev=532491&r1=532490&r2=532491
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp Wed Apr 25 14:26:53 2007
@@ -54,18 +54,27 @@
 
     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) {
+            // Make it clear this is an env. var problem, the
+            // exception from boost::program_options doesn't.
+            throw logic_error(string(e.what())+" (parsing environment variables)");
+        }
         po::notify(vm);
     };
     
-    void usage(std::ostream& out) const {
+    void usage(ostream& out) const {
         out << "Usage: qpidd [OPTIONS]" << endl 
             << "Start the Qpid AMQP broker." << endl << endl
             << desc << endl;
     };
 };
 
-std::ostream& operator<<(std::ostream& out, const QpiddOptions& config)
 {
+ostream& operator<<(ostream& out, const QpiddOptions& config)  {
     config.usage(out); return out;
 }
 



Mime
View raw message