Commit f3e37b9e authored by Guolin Ke's avatar Guolin Ke
Browse files

better parameter parse logic.

parent 8de2bac5
......@@ -58,7 +58,7 @@ Application::~Application() {
void Application::LoadParameters(int argc, char** argv) {
std::unordered_map<std::string, std::string> params;
for (int i = 0; i < argc; ++i) {
for (int i = 1; i < argc; ++i) {
std::vector<std::string> tmp_strs = Common::Split(argv[i], '=');
if (tmp_strs.size() == 2) {
std::string key = Common::RemoveQuotationSymbol(Common::Trim(tmp_strs[0]));
......@@ -68,6 +68,9 @@ void Application::LoadParameters(int argc, char** argv) {
}
params[key] = value;
}
else {
Log::Stdout("Warning: unknown parameter in command line: %s", argv[i]);
}
}
// check for alias
ParameterAlias::KeyAliasTransform(&params);
......@@ -77,9 +80,12 @@ void Application::LoadParameters(int argc, char** argv) {
config_reader.ReadAllLines();
if (config_reader.Lines().size() > 0) {
for (auto& line : config_reader.Lines()) {
// remove str after #
if (line.size() > 0 && std::string::npos != line.find_first_of("#")) {
line.erase(line.find_first_of("#"));
}
line = Common::Trim(line);
// skip comment
if (line.size() == 0 || line[0] == '#') {
if (line.size() == 0) {
continue;
}
std::vector<std::string> tmp_strs = Common::Split(line.c_str(), '=');
......@@ -94,6 +100,9 @@ void Application::LoadParameters(int argc, char** argv) {
params[key] = value;
}
}
else {
Log::Stdout("Warning: unknown parameter in config file: %s", line.c_str());
}
}
} else {
Log::Stdout("config file: %s doesn't exist, will ignore",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment