Make use of a default value

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
Thomas Lauf 2019-04-11 10:46:39 +02:00
parent a672fd0647
commit 6f439097d6
3 changed files with 15 additions and 17 deletions

View file

@ -141,13 +141,16 @@ bool Rules::has (const std::string& key) const
////////////////////////////////////////////////////////////////////////////////
// Return the configuration value given the specified key.
std::string Rules::get (const std::string& key) const
std::string Rules::get (const std::string &key, const std::string &defaultValue) const
{
auto found = _settings.find (key);
if (found != _settings.end ())
return found->second;
return "";
if (found != _settings.end ())
{
return found->second;
}
return defaultValue;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -41,7 +41,7 @@ public:
std::string file () const;
bool has (const std::string&) const;
std::string get (const std::string&) const;
std::string get (const std::string &key, const std::string &defaultValue = "") const;
int getInteger (const std::string&, int defaultValue = 0) const;
double getReal (const std::string&) const;
bool getBoolean (const std::string&) const;
@ -78,6 +78,7 @@ private:
std::string _original_file {};
std::map <std::string, std::string> _settings {};
std::vector <std::string> _rule_types {"tags", "reports", "theme", "holidays", "exclusions"};
};
#endif

View file

@ -47,12 +47,10 @@ int CmdChartDay (
{
// Create a filter, and if empty, choose the current day.
auto filter = getFilter (cli);
if (! filter.is_started ())
{
if (rules.has ("reports.day.range"))
expandIntervalHint (rules.get ("reports.day.range"), filter);
else
filter.setRange (Datetime ("today"), Datetime ("tomorrow"));
expandIntervalHint (rules.get ("reports.day.range", ":day"), filter);
}
return renderChart (cli, "day", filter, rules, database);
@ -66,12 +64,10 @@ int CmdChartWeek (
{
// Create a filter, and if empty, choose the current week.
auto filter = getFilter (cli);
if (! filter.is_started ())
{
if (rules.has ("reports.week.range"))
expandIntervalHint (rules.get ("reports.week.range"), filter);
else
filter.setRange (Datetime ("sow"), Datetime ("eow"));
expandIntervalHint (rules.get ("reports.week.range", ":week"), filter);
}
return renderChart (cli, "week", filter, rules, database);
@ -85,12 +81,10 @@ int CmdChartMonth (
{
// Create a filter, and if empty, choose the current month.
auto filter = getFilter (cli);
if (! filter.is_started ())
{
if (rules.has ("reports.month.range"))
expandIntervalHint (rules.get ("reports.month.range"), filter);
else
filter.setRange (Datetime ("som"), Datetime ("eom"));
expandIntervalHint (rules.get ("reports.month.range", ":month"), filter);
}
return renderChart (cli, "month", filter, rules, database);