18namespace entropic::config {
29 return std::string(
s.str,
s.len);
39std::string
read_file(
const std::filesystem::path& path)
41 std::ifstream
ifs(path);
43 s_log->error(
"Cannot open file: {}", path.string());
46 std::ostringstream
ss;
48 auto content =
ss.str();
49 s_log->info(
"Read file: {}, {} bytes", path.string(),
63 auto str =
p.string();
64 const char*
home = std::getenv(
"HOME");
71 return (
str.size() == 1)
72 ? std::filesystem::path(
home)
73 : std::filesystem::path(
home) /
str.substr(2);
85bool extract(ryml::ConstNodeRef
node, c4::csubstr key, std::string& out)
87 if (!
node.is_map() || !
node.has_child(key)) {
109 if (!
node.is_map() || !
node.has_child(key)) {
113 if (!
child.has_val() ||
child.val_is_null()) {
117 out = std::stoi(
val);
132 if (!
node.is_map() || !
node.has_child(key)) {
136 if (!
child.has_val() ||
child.val_is_null()) {
140 out = std::stof(
val);
153bool extract(ryml::ConstNodeRef
node, c4::csubstr key,
double& out)
155 if (!
node.is_map() || !
node.has_child(key)) {
159 if (!
child.has_val() ||
child.val_is_null()) {
163 out = std::stod(
val);
178 if (!
node.is_map() || !
node.has_child(key)) {
182 if (!
child.has_val() ||
child.val_is_null()) {
186 out = (
val ==
"true" ||
val ==
"True" ||
val ==
"TRUE"
187 ||
val ==
"yes" ||
val ==
"Yes" ||
val ==
"YES"
188 ||
val ==
"on" ||
val ==
"On" ||
val ==
"ON"
203 std::filesystem::path& out)
224 ryml::ConstNodeRef
node, c4::csubstr key,
225 std::optional<std::filesystem::path>& out,
bool&
disabled)
227 if (!
node.is_map() || !
node.has_child(key)) {
258 ryml::ConstNodeRef
node, c4::csubstr key, std::optional<std::string>& out)
261 if (
node.is_map() &&
node.has_child(key)) {
263 if (
child.is_map() &&
child.has_child(
"content")) {
264 auto content =
child[
"content"];
265 if (content.has_val()) {
284 std::vector<std::string>& out)
286 if (!
node.is_map() || !
node.has_child(key)) {
290 if (!
child.is_seq()) {
310 std::optional<std::vector<std::string>>& out)
312 if (!
node.is_map() || !
node.has_child(key)) {
316 if (!
child.is_seq()) {
318 out =
is_null ? std::nullopt : out;
321 std::vector<std::string>
vec;
325 out = std::move(
vec);
339 std::unordered_map<std::string, std::string>& out)
341 if (!
node.is_map() || !
node.has_child(key)) {
345 if (!
child.is_map()) {
365 ryml::ConstNodeRef
node, c4::csubstr key,
366 std::unordered_map<std::string, std::vector<std::string>>& out)
368 if (!
node.is_map() || !
node.has_child(key)) {
372 if (!
child.is_map()) {
377 std::vector<std::string>
vec;
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
@ disabled
Named in disabled_mcpjson_servers — never connect.
@ optional
optional: every escape asks the host's path approver
std::filesystem::path expand_home(const std::filesystem::path &p)
Expand ~ to home directory in a path.
bool extract_string_list_map(ryml::ConstNodeRef node, c4::csubstr key, std::unordered_map< std::string, std::vector< std::string > > &out)
Extract a map of string to list of strings from a YAML mapping.
bool extract_inline_content(ryml::ConstNodeRef node, c4::csubstr key, std::optional< std::string > &out)
Extract inline text from an object-form value (gh#141).
std::string read_file(const std::filesystem::path &path)
Read a file into a string.
bool extract_path(ryml::ConstNodeRef node, c4::csubstr key, std::filesystem::path &out)
Extract a filesystem path with ~ expansion.
bool extract_string_list(ryml::ConstNodeRef node, c4::csubstr key, std::vector< std::string > &out)
Extract a vector of strings from a YAML sequence node.
bool extract_string_map(ryml::ConstNodeRef node, c4::csubstr key, std::unordered_map< std::string, std::string > &out)
Extract a map of string to string from a YAML mapping node.
bool extract_string_list_opt(ryml::ConstNodeRef node, c4::csubstr key, std::optional< std::vector< std::string > > &out)
Extract an optional vector of strings.
bool extract_tri_state_path(ryml::ConstNodeRef node, c4::csubstr key, std::optional< std::filesystem::path > &out, bool &disabled)
Extract a tri-state path (null = default, false = disabled, string = path).
std::string to_string(c4::csubstr s)
Convert ryml csubstr to std::string.
bool extract(ryml::ConstNodeRef node, c4::csubstr key, std::string &out)
Extract a string value from a YAML node.
ryml extraction helpers for config parsing.