Last active
August 29, 2015 14:07
-
-
Save jazzdan/08611f19a61dfb010bad to your computer and use it in GitHub Desktop.
Add option to HHVM similar to --with-config-file-scan-dir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 0c41732a7ca14b15437f115c51b06e829988f048 | |
Author: Dan Miller <[email protected]> | |
Date: Fri Oct 3 16:27:06 2014 +0000 | |
Add config-scan-dir option | |
diff --git a/hphp/runtime/base/program-functions.cpp b/hphp/runtime/base/program-functions.cpp | |
index b97e086..ba803f6 100644 | |
--- a/hphp/runtime/base/program-functions.cpp | |
+++ b/hphp/runtime/base/program-functions.cpp | |
@@ -66,6 +66,7 @@ | |
#include "hphp/runtime/base/config.h" | |
#include "hphp/runtime/base/backtrace.h" | |
+#include <boost/filesystem.hpp> | |
#include <boost/program_options/options_description.hpp> | |
#include <boost/program_options/positional_options.hpp> | |
#include <boost/program_options/variables_map.hpp> | |
@@ -122,6 +123,8 @@ struct ProgramOptions { | |
std::vector<std::string> | |
config; | |
std::vector<std::string> | |
+ config_scan_dir; | |
+ std::vector<std::string> | |
confStrings; | |
std::vector<std::string> | |
iniStrings; | |
@@ -215,6 +218,41 @@ void process_ini_file(const std::string& filename) { | |
process_ini_settings(str, filename); | |
} | |
+void process_ini_directory(const std::string& directory) { | |
+ if (directory.empty()) { | |
+ return; | |
+ } | |
+ | |
+ boost::filesystem::path filepath(directory.c_str()); | |
+ vector<boost::filesystem::path> paths; | |
+ | |
+ std::copy(boost::filesystem::directory_iterator(filepath), boost::filesystem::directory_iterator(), std::back_inserter(paths)); | |
+ std::sort(paths.begin(), paths.end()); | |
+ | |
+ for (vector<boost::filesystem::path>::const_iterator it(paths.begin()); it != paths.end(); ++it) { | |
+ process_ini_file((*it).string()); | |
+ } | |
+} | |
+ | |
void process_ini_settings(const std::string& ini_str, | |
const std::string& filename /* = "" */) { | |
auto settings = IniSetting::FromStringAsMap(ini_str, filename); | |
@@ -1088,6 +1126,8 @@ static int execute_program_impl(int argc, char** argv) { | |
("interactive,a", "Shortcut for --mode debug") // -a is from PHP5 | |
("config,c", value<vector<string> >(&po.config)->composing(), | |
"load specified config file") | |
+ ("config-scan-dir", value<vector<string> >(&po.config_scan_dir)->composing(), | |
+ "load configs from directory") | |
("config-value,v", | |
value<std::vector<std::string>>(&po.confStrings)->composing(), | |
"individual configuration string in a format of name=value, where " | |
@@ -1282,6 +1322,9 @@ static int execute_program_impl(int argc, char** argv) { | |
for (auto& c : po.config) { | |
process_ini_file(c); | |
} | |
+ for (auto& c : po.config_scan_dir) { | |
+ process_ini_directory(c); | |
+ } | |
for (auto& istr : po.iniStrings) { | |
process_ini_settings(istr, ""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment