From 63bbe857c8707e73faee2ecd2f29b218387b2d7c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 2 Feb 2016 01:03:56 -0500 Subject: [PATCH] Config: No longer autovivifies --- src/Config.cpp | 23 +++++++++++++++-------- test/show.t | 1 + test/uda.t | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index 4c649abd9..035059cf0 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -554,14 +554,19 @@ bool Config::has (const std::string& key) // Return the configuration value given the specified key. std::string Config::get (const std::string& key) { - return (*this)[key]; + auto found = find (key); + if (found != end ()) + return found->second; + + return ""; } //////////////////////////////////////////////////////////////////////////////// int Config::getInteger (const std::string& key) { - if ((*this).find (key) != (*this).end ()) - return strtoimax ((*this)[key].c_str (), NULL, 10); + auto found = find (key); + if (found != end ()) + return strtoimax (found->second.c_str (), nullptr, 10); return 0; } @@ -571,11 +576,12 @@ double Config::getReal (const std::string& key) { //NOTE: Backwards compatible handling of next coefficient. //TODO: Remove. - if (key == "urgency.user.tag.next.coefficient" and has("urgency.next.coefficient")) - return getReal("urgency.next.coefficient"); + if (key == "urgency.user.tag.next.coefficient" and has ("urgency.next.coefficient")) + return getReal ("urgency.next.coefficient"); - if ((*this).find (key) != (*this).end ()) - return strtod ((*this)[key].c_str (), NULL); + auto found = find (key); + if (found != end ()) + return strtod (found->second.c_str (), nullptr); return 0.0; } @@ -583,7 +589,8 @@ double Config::getReal (const std::string& key) //////////////////////////////////////////////////////////////////////////////// bool Config::getBoolean (const std::string& key) { - if ((*this).find (key) != (*this).end ()) + auto found = find (key); + if (found != end ()) { std::string value = Lexer::lowerCase ((*this)[key]); if (value == "t" || // TODO Deprecate diff --git a/test/show.t b/test/show.t index ed744e09c..1631d3b55 100755 --- a/test/show.t +++ b/test/show.t @@ -54,6 +54,7 @@ class TestShowCommand(TestCase): def test_show_one_arg(self): """Verify show command lists one result with an arg provided""" + self.t.config("default.due", "tomorrow") code, out, err = self.t("show default.due") self.assertNotIn("default.command", out) self.assertIn("default.due", out) diff --git a/test/uda.t b/test/uda.t index fa1e5f985..04866a41f 100755 --- a/test/uda.t +++ b/test/uda.t @@ -51,6 +51,7 @@ class TestBaseUda(TestCase): class TestUdaCommand(TestBaseUda): def setUp(self): super(TestUdaCommand, self).setUp() + self.t.config("uda.extra.type", "string") def test_uda_command(self): """The 'udas' command should list 'priority' and 'extra'"""