-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Included file path is based on including file directory #114
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1. compile the code | ||
2. run binary in "bin" or in "conf" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <hocon/parser/config_document_factory.hpp> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be moved to the |
||
#include <hocon/config.hpp> | ||
|
||
#include <iostream> | ||
#include <set> | ||
|
||
using namespace hocon; | ||
using namespace std; | ||
|
||
int main() { | ||
auto conf_file = config::parse_file_any_syntax("../conf/a.conf"); | ||
auto conf = conf_file->resolve(); | ||
auto conf2 = config::parse_file_any_syntax("../conf/sub/b.conf")->resolve(); | ||
try { | ||
auto str = conf->get_string("Peter.passwd1"); | ||
cout << "peter's passwd:" << str << endl; | ||
cout << "peter's passwd2:" << conf->get_string("Peter.passwd2") << endl; | ||
cout << "peter's passwd3:" << conf->get_string("Peter.passwd3") << endl; | ||
cout << "peter's passwd4:" << conf->get_string("Peter.passwd4") << endl; | ||
|
||
cout << "nick_name:" << conf2->get_string("other_field.nick_name") << endl; | ||
} catch (hocon::config_exception& e) { | ||
cout << "ERROR:" << e.what() << endl; | ||
} | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of |
||
include file("d.conf") | ||
Peter : { | ||
include file("b.conf") | ||
include file("sub/b.conf") | ||
passwd4 : ${new_passwd} | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
passwd1 : "adsf" | ||
include file("/export/source_code/cpp-hocon/test/example/conf/sub/c.conf") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
new_passwd : "qwer.,m" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
passwd2 : "lsdk" , | ||
|
||
other_field : { | ||
include file("e.conf") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
passwd3 : "123414", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
nick_name : nick | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
#include <hocon/config_exception.hpp> | ||
#include <internal/default_transformer.hpp> | ||
#include <internal/resolve_context.hpp> | ||
#include <internal/config_util.hpp> | ||
#include <internal/values/config_boolean.hpp> | ||
#include <internal/values/config_null.hpp> | ||
#include <internal/values/config_number.hpp> | ||
|
@@ -29,13 +30,27 @@ using namespace std; | |
|
||
namespace hocon { | ||
|
||
shared_config config::parse_file_any_syntax(std::string file_basename, config_parse_options options) { | ||
shared_config config::parse_file_any_syntax(std::string file_basename, config_parse_options options, shared_full_current fpath) { | ||
std::string file_dir(""), file_name(""); | ||
if (nullptr == fpath) { | ||
fpath = make_shared<full_path_operator>(); | ||
} | ||
extract_filename_from_path(file_basename, &file_dir, &file_name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My instinct is that this isn't the place we should be fixing this, but it'd take some work for me to follow up on. From a quick glance at https://github.com/lightbend/config/blob/7b9e1539dd46385e9b83be43c4112a448129ac2f/config/src/main/java/com/typesafe/config/impl/Parseable.java#L639-L655, I think the mistake may be in not overriding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for code-reviewing and comments. I think we could left the problem open before solved. And I'll keep trying to figure another way out to fix it. Thanks again~ |
||
if (file_name.empty()) { | ||
throw config_exception(_("can not find file '{1}' in Dir '{2}'", file_name, file_dir)); | ||
} | ||
|
||
auto source = make_shared<file_name_source>(); | ||
return simple_includer::from_basename(move(source), move(file_basename), move(options))->to_config(); | ||
fpath->append(file_dir); | ||
auto ret = simple_includer::from_basename(move(source), fpath->extend(file_name), move(options), fpath)->to_config(); | ||
if (fpath->remove(file_dir)) { | ||
throw config_exception(_("removing file dir error")); | ||
} | ||
return ret; | ||
} | ||
|
||
shared_config config::parse_file_any_syntax(std::string file_basename) { | ||
return parse_file_any_syntax(move(file_basename), config_parse_options::defaults()); | ||
return parse_file_any_syntax(move(file_basename), config_parse_options::defaults(), nullptr); | ||
} | ||
|
||
shared_config config::parse_string(string s, config_parse_options options) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably makes more sense as the commit message rather than part of the README.