Extract function getDomReferences and move it to CLI

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
Thomas Lauf 2020-05-08 13:47:39 +02:00
parent 29cc9e8a0a
commit 422e49bacb
3 changed files with 25 additions and 11 deletions

View file

@ -606,3 +606,19 @@ Duration CLI::getDuration () const
}
////////////////////////////////////////////////////////////////////////////////
std::vector <std::string> CLI::getDomReferences () const
{
std::vector<std::string> references;
for (auto &arg : _args)
{
if (arg.hasTag ("TAG") &&
arg.hasTag ("FILTER"))
{
references.emplace_back (arg.attribute ("raw"));
}
}
return references;
}

View file

@ -70,6 +70,7 @@ public:
std::vector<std::string> getTags () const;
std::string getAnnotation() const;
Duration getDuration() const;
std::vector<std::string> getDomReferences () const;
std::string dump (const std::string& title = "CLI Parser") const;
private:

View file

@ -38,18 +38,15 @@ int CmdGet (
Database& database)
{
std::vector <std::string> results;
for (auto& arg : cli._args)
{
if (arg.hasTag ("TAG") &&
arg.hasTag ("FILTER"))
{
std::string reference = arg.attribute ("raw");
std::string value;
if (! domGet (database, rules, reference, value))
throw format ("DOM reference '{1}' is not valid.", reference);
std::vector <std::string> references = cli.getDomReferences ();
results.push_back (value);
}
for (auto& reference : references)
{
std::string value;
if (! domGet (database, rules, reference, value))
throw format ("DOM reference '{1}' is not valid.", reference);
results.push_back (value);
}
std::cout << join (" ", results) << '\n';