From 980fdf5d3dbedfc05749670f1a47b2f6ea6c0dd6 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:56:54 +0200 Subject: [PATCH] Indented toml config files for improved legibility --- nano/lib/tomlconfig.cpp | 21 ++++++++++----------- nano/lib/tomlconfig.hpp | 3 +-- nano/node/cli.cpp | 4 ++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/nano/lib/tomlconfig.cpp b/nano/lib/tomlconfig.cpp index ee8d9e6f28..3cace0d655 100644 --- a/nano/lib/tomlconfig.cpp +++ b/nano/lib/tomlconfig.cpp @@ -186,15 +186,7 @@ void nano::tomlconfig::erase_default_values (tomlconfig & defaults_a) erase_defaults (defaults_l.get_tree (), self.get_tree (), get_tree ()); } -std::string nano::tomlconfig::to_string () -{ - std::stringstream ss; - cpptoml::toml_writer writer{ ss, "" }; - tree->accept (writer); - return ss.str (); -} - -std::string nano::tomlconfig::to_string_commented_entries () +std::string nano::tomlconfig::to_string (bool comment_values) { std::stringstream ss, ss_processed; cpptoml::toml_writer writer{ ss, "" }; @@ -202,9 +194,16 @@ std::string nano::tomlconfig::to_string_commented_entries () std::string line; 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; } diff --git a/nano/lib/tomlconfig.hpp b/nano/lib/tomlconfig.hpp index 140e1b0ab9..41ac0647b1 100644 --- a/nano/lib/tomlconfig.hpp +++ b/nano/lib/tomlconfig.hpp @@ -47,8 +47,7 @@ class tomlconfig : public nano::configbase tomlconfig & erase (std::string const & key_a); std::shared_ptr create_array (std::string const & key, boost::optional documentation_a); void erase_default_values (tomlconfig & defaults_a); - std::string to_string (); - std::string to_string_commented_entries (); + std::string to_string (bool comment_values); /** Set value for the given key. Any existing value will be overwritten. */ template diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index df480e560b..f58722cfc2 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -703,11 +703,11 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map if (vm.count ("use_defaults")) { - std::cout << toml.to_string () << std::endl; + std::cout << toml.to_string (false) << std::endl; } else { - std::cout << toml.to_string_commented_entries () << std::endl; + std::cout << toml.to_string (true) << std::endl; } } }