Indented toml config files for improved legibility (#4558)
This commit is contained in:
parent
9be56a67f2
commit
e9eaaef66a
3 changed files with 13 additions and 15 deletions
|
|
@ -186,15 +186,7 @@ void nano::tomlconfig::erase_default_values (tomlconfig & defaults_a)
|
||||||
erase_defaults (defaults_l.get_tree (), self.get_tree (), get_tree ());
|
erase_defaults (defaults_l.get_tree (), self.get_tree (), get_tree ());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string nano::tomlconfig::to_string ()
|
std::string nano::tomlconfig::to_string (bool comment_values)
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
cpptoml::toml_writer writer{ ss, "" };
|
|
||||||
tree->accept (writer);
|
|
||||||
return ss.str ();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string nano::tomlconfig::to_string_commented_entries ()
|
|
||||||
{
|
{
|
||||||
std::stringstream ss, ss_processed;
|
std::stringstream ss, ss_processed;
|
||||||
cpptoml::toml_writer writer{ ss, "" };
|
cpptoml::toml_writer writer{ ss, "" };
|
||||||
|
|
@ -202,9 +194,16 @@ std::string nano::tomlconfig::to_string_commented_entries ()
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline (ss, line, '\n'))
|
while (std::getline (ss, line, '\n'))
|
||||||
{
|
{
|
||||||
if (!line.empty () && line[0] != '#' && line[0] != '[')
|
if (!line.empty () && line[0] != '[')
|
||||||
{
|
{
|
||||||
line = "#" + line;
|
if (line[0] == '#') // Already commented
|
||||||
|
{
|
||||||
|
line = "\t" + line;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
line = comment_values ? "\t# " + line : "\t" + line;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ss_processed << line << std::endl;
|
ss_processed << line << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,7 @@ public:
|
||||||
tomlconfig & erase (std::string const & key_a);
|
tomlconfig & erase (std::string const & key_a);
|
||||||
std::shared_ptr<cpptoml::array> create_array (std::string const & key, boost::optional<char const *> documentation_a);
|
std::shared_ptr<cpptoml::array> create_array (std::string const & key, boost::optional<char const *> documentation_a);
|
||||||
void erase_default_values (tomlconfig & defaults_a);
|
void erase_default_values (tomlconfig & defaults_a);
|
||||||
std::string to_string ();
|
std::string to_string (bool comment_values);
|
||||||
std::string to_string_commented_entries ();
|
|
||||||
|
|
||||||
/** Set value for the given key. Any existing value will be overwritten. */
|
/** Set value for the given key. Any existing value will be overwritten. */
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
||||||
|
|
@ -703,11 +703,11 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
||||||
|
|
||||||
if (vm.count ("use_defaults"))
|
if (vm.count ("use_defaults"))
|
||||||
{
|
{
|
||||||
std::cout << toml.to_string () << std::endl;
|
std::cout << toml.to_string (false) << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << toml.to_string_commented_entries () << std::endl;
|
std::cout << toml.to_string (true) << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue