summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/CommonOptions.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-04-25 21:26:53 +0000
committerAlan Conway <aconway@apache.org>2007-04-25 21:26:53 +0000
commitd0cfa8d4724bd5f5f018d923d62d9bea87cdcb80 (patch)
tree4bc00d56b87042316db72b7bc3bb65df6a37ff76 /cpp/src/qpid/CommonOptions.cpp
parentaefcbcdd3f930f4934b022df6b214d6a62f81d35 (diff)
downloadqpid-python-d0cfa8d4724bd5f5f018d923d62d9bea87cdcb80.tar.gz
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. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@532491 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/CommonOptions.cpp')
-rw-r--r--cpp/src/qpid/CommonOptions.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/cpp/src/qpid/CommonOptions.cpp b/cpp/src/qpid/CommonOptions.cpp
index 8efb3a6baa..d4db3660bd 100644
--- a/cpp/src/qpid/CommonOptions.cpp
+++ b/cpp/src/qpid/CommonOptions.cpp
@@ -17,9 +17,29 @@
*/
#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;
CommonOptions::CommonOptions() : trace(false), port(DEFAULT_PORT) {}