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 <file.hpp>
10 :
11 : #include <cmdline.hpp>
12 : #include <kdb.hpp>
13 : #include <kdblogger.h>
14 :
15 : #include <iostream>
16 :
17 : using namespace std;
18 : using namespace kdb;
19 :
20 354 : FileCommand::FileCommand ()
21 : {
22 354 : }
23 :
24 276 : int FileCommand::execute (Cmdline const & cl)
25 : {
26 552 : if (cl.arguments.size () != 1) throw invalid_argument ("Need one argument");
27 :
28 552 : KeySet conf;
29 552 : Key x = cl.createKey (0);
30 828 : if (x.getName ()[0] == '/')
31 : {
32 333 : x.setName (cl.ns + x.getName ());
33 555 : std::cerr << "Using name " << x.getName () << std::endl;
34 : }
35 276 : if (!x.isValid ())
36 : {
37 0 : throw invalid_argument (cl.arguments[0] + " is not a valid keyname");
38 : }
39 :
40 : try
41 : {
42 276 : kdb.get (conf, x);
43 : }
44 8 : catch (KDBException const & exception)
45 : {
46 : // The command should return the filename even if the config file contains syntax errors
47 : ELEKTRA_LOG_WARNING ("Get returned with an exception: %s", exception.what ());
48 : }
49 828 : cout << x.getString ();
50 :
51 276 : if (!cl.noNewline)
52 : {
53 : cout << endl;
54 : }
55 :
56 552 : return 0;
57 : }
58 :
59 708 : FileCommand::~FileCommand ()
60 : {
61 7518 : }
|