Config: No longer autovivifies

This commit is contained in:
Paul Beckingham 2016-02-02 01:03:56 -05:00
parent 23ac9895ab
commit 63bbe857c8
3 changed files with 17 additions and 8 deletions

View file

@ -554,14 +554,19 @@ bool Config::has (const std::string& key)
// Return the configuration value given the specified key. // Return the configuration value given the specified key.
std::string Config::get (const std::string& 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) int Config::getInteger (const std::string& key)
{ {
if ((*this).find (key) != (*this).end ()) auto found = find (key);
return strtoimax ((*this)[key].c_str (), NULL, 10); if (found != end ())
return strtoimax (found->second.c_str (), nullptr, 10);
return 0; return 0;
} }
@ -571,11 +576,12 @@ double Config::getReal (const std::string& key)
{ {
//NOTE: Backwards compatible handling of next coefficient. //NOTE: Backwards compatible handling of next coefficient.
//TODO: Remove. //TODO: Remove.
if (key == "urgency.user.tag.next.coefficient" and has("urgency.next.coefficient")) if (key == "urgency.user.tag.next.coefficient" and has ("urgency.next.coefficient"))
return getReal("urgency.next.coefficient"); return getReal ("urgency.next.coefficient");
if ((*this).find (key) != (*this).end ()) auto found = find (key);
return strtod ((*this)[key].c_str (), NULL); if (found != end ())
return strtod (found->second.c_str (), nullptr);
return 0.0; return 0.0;
} }
@ -583,7 +589,8 @@ double Config::getReal (const std::string& key)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Config::getBoolean (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]); std::string value = Lexer::lowerCase ((*this)[key]);
if (value == "t" || // TODO Deprecate if (value == "t" || // TODO Deprecate

View file

@ -54,6 +54,7 @@ class TestShowCommand(TestCase):
def test_show_one_arg(self): def test_show_one_arg(self):
"""Verify show command lists one result with an arg provided""" """Verify show command lists one result with an arg provided"""
self.t.config("default.due", "tomorrow")
code, out, err = self.t("show default.due") code, out, err = self.t("show default.due")
self.assertNotIn("default.command", out) self.assertNotIn("default.command", out)
self.assertIn("default.due", out) self.assertIn("default.due", out)

View file

@ -51,6 +51,7 @@ class TestBaseUda(TestCase):
class TestUdaCommand(TestBaseUda): class TestUdaCommand(TestBaseUda):
def setUp(self): def setUp(self):
super(TestUdaCommand, self).setUp() super(TestUdaCommand, self).setUp()
self.t.config("uda.extra.type", "string")
def test_uda_command(self): def test_uda_command(self):
"""The 'udas' command should list 'priority' and 'extra'""" """The 'udas' command should list 'priority' and 'extra'"""