LCOV - code coverage report
Current view: top level - src/tools/kdb - metaget.cpp (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 18 19 94.7 %
Date: 2019-09-12 12:28:41 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /**
       2             :  * @file
       3             :  *
       4             :  * @brief
       5             :  *
       6             :  * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
       7             :  */
       8             : 
       9             : #include <metaget.hpp>
      10             : 
      11             : #include <cmdline.hpp>
      12             : #include <kdb.hpp>
      13             : 
      14             : #include <iostream>
      15             : #include <string>
      16             : 
      17             : using namespace std;
      18             : using namespace kdb;
      19             : 
      20         108 : MetaGetCommand::MetaGetCommand ()
      21             : {
      22         108 : }
      23             : 
      24          30 : int MetaGetCommand::execute (Cmdline const & cl)
      25             : {
      26          60 :         if (cl.arguments.size () != 2)
      27             :         {
      28           0 :                 throw invalid_argument ("Need 2 arguments");
      29             :         }
      30          60 :         Key parentKey = cl.createKey (0);
      31          90 :         string metaname = cl.arguments[1];
      32             : 
      33          60 :         KeySet conf;
      34          30 :         kdb.get (conf, parentKey);
      35          30 :         printWarnings (cerr, parentKey, cl.verbose, cl.debug);
      36             : 
      37          60 :         Key k = conf.lookup (parentKey);
      38             : 
      39          30 :         if (!k)
      40             :         {
      41           2 :                 cerr << "Key not found" << endl;
      42             :                 return 1;
      43             :         }
      44             : 
      45          84 :         if (!k.getMeta<const Key> (metaname))
      46             :         {
      47           1 :                 cerr << "Metakey not found" << endl;
      48             :                 return 2;
      49             :         }
      50             : 
      51          81 :         cout << k.getMeta<string> (metaname);
      52             : 
      53          27 :         if (!cl.noNewline)
      54             :         {
      55             :                 cout << endl;
      56             :         }
      57             : 
      58             :         return 0;
      59             : }
      60             : 
      61         216 : MetaGetCommand::~MetaGetCommand ()
      62             : {
      63        7272 : }

Generated by: LCOV version 1.13