diff --git a/include/components/config_parser.hpp b/include/components/config_parser.hpp index 35c56781..f580f0eb 100644 --- a/include/components/config_parser.hpp +++ b/include/components/config_parser.hpp @@ -90,12 +90,12 @@ struct line_t { class config_parser { public: - config_parser(const logger& logger, string&& file, string&& bar); + config_parser(const logger& logger, string&& file); /** * This prevents passing a temporary logger to the constructor because that would be UB, as the temporary would be * destroyed once the constructor returns. */ - config_parser(logger&& logger, string&& file, string&& bar) = delete; + config_parser(logger&& logger, string&& file) = delete; /** * @brief Performs the parsing of the main config file m_file @@ -105,7 +105,7 @@ class config_parser { * @throws syntax_error If there was any kind of syntax error * @throws parser_error If aynthing else went wrong */ - config::make_type parse(); + config::make_type parse(string barname); protected: /** @@ -231,11 +231,6 @@ class config_parser { */ string m_config; - /** - * Is used to resolve ${root...} references - */ - string m_barname; - /** * @brief List of all the lines in the config (with included files) * diff --git a/src/components/config_parser.cpp b/src/components/config_parser.cpp index d29a2319..6403bb1a 100644 --- a/src/components/config_parser.cpp +++ b/src/components/config_parser.cpp @@ -10,10 +10,10 @@ POLYBAR_NS -config_parser::config_parser(const logger& logger, string&& file, string&& bar) - : m_log(logger), m_config(file_util::expand(file)), m_barname(move(bar)) {} +config_parser::config_parser(const logger& logger, string&& file) + : m_log(logger), m_config(file_util::expand(file)) {} -config::make_type config_parser::parse() { +config::make_type config_parser::parse(string barname) { m_log.notice("Parsing config file: %s", m_config); parse_file(m_config, {}); @@ -21,21 +21,21 @@ config::make_type config_parser::parse() { sectionmap_t sections = create_sectionmap(); vector bars = get_bars(sections); - if (m_barname.empty()) { + if (barname.empty()) { if (bars.size() == 1) { - m_barname = bars[0]; + barname = bars[0]; } else if (bars.empty()) { throw application_error("The config file contains no bar."); } else { throw application_error("The config file contains multiple bars, but no bar name was given. Available bars: " + string_util::join(bars, ", ")); } - } else if (sections.find("bar/" + m_barname) == sections.end()) { + } else if (sections.find("bar/" + barname) == sections.end()) { if (bars.empty()) { - throw application_error("Undefined bar: " + m_barname + ". The config file contains no bar."); + throw application_error("Undefined bar: " + barname + ". The config file contains no bar."); } else { throw application_error( - "Undefined bar: " + m_barname + ". Available bars: " + string_util::join(get_bars(sections), ", ")); + "Undefined bar: " + barname + ". Available bars: " + string_util::join(get_bars(sections), ", ")); } } @@ -45,7 +45,7 @@ config::make_type config_parser::parse() { * second element onwards for the included list */ file_list included(m_files.begin() + 1, m_files.end()); - config::make_type result = config::make(m_config, m_barname); + config::make_type result = config::make(m_config, barname); // Cast to non-const to set sections, included and xrm config& m_conf = const_cast(result); diff --git a/src/main.cpp b/src/main.cpp index e2aa9e1e..203bc49d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -127,8 +127,8 @@ int main(int argc, char** argv) { barname = cli->get(0); } - config_parser parser{logger, move(confpath), move(barname)}; - config::make_type conf = parser.parse(); + config_parser parser{logger, move(confpath)}; + config::make_type conf = parser.parse(move(barname)); //================================================== // Dump requested data diff --git a/tests/unit_tests/components/config_parser.cpp b/tests/unit_tests/components/config_parser.cpp index 05d55220..a3d1cbe9 100644 --- a/tests/unit_tests/components/config_parser.cpp +++ b/tests/unit_tests/components/config_parser.cpp @@ -13,8 +13,8 @@ class TestableConfigParser : public config_parser { using config_parser::config_parser; public: - TestableConfigParser(const logger& logger, string&& file, string&& bar) - : config_parser(logger, move(file), move(bar)) { + TestableConfigParser(const logger& logger, string&& file) + : config_parser(logger, move(file)) { m_files.push_back("test_config"); } @@ -43,7 +43,7 @@ class TestableConfigParser : public config_parser { class ConfigParser : public ::testing::Test { protected: const logger l = logger(loglevel::NONE); - unique_ptr parser = make_unique(l, "/dev/zero", "TEST"); + unique_ptr parser = make_unique(l, "/dev/zero"); }; // ParseLineTest {{{