Commands: Reduce code duplication

- Extract function to gather ids
This commit is contained in:
Thomas Lauf 2017-11-21 23:12:45 +01:00
parent c5b2e5a5cd
commit dc6d3b9672
13 changed files with 70 additions and 81 deletions

View file

@ -39,21 +39,20 @@ int CmdLengthen (
Database& database)
{
// Gather IDs and TAGs.
std::vector <int> ids;
std::vector <int> ids = cli.getIds();
if (ids.empty ())
throw std::string ("IDs must be specified. See 'timew help lengthen'.");
std::string delta;
for (auto& arg : cli._args)
{
if (arg.hasTag ("ID"))
ids.push_back (strtol (arg.attribute ("value").c_str (), NULL, 10));
if (arg.hasTag ("FILTER") &&
arg._lextype == Lexer::Type::duration)
delta = arg.attribute ("raw");
}
if (! ids.size ())
throw std::string ("IDs must be specified. See 'timew help lengthen'.");
// Load the data.
// Note: There is no filter.
Interval filter;