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 <sget.hpp>
10 :
11 : #include <cmdline.hpp>
12 : #include <kdb.hpp>
13 :
14 : #include <iostream>
15 :
16 : using namespace std;
17 : using namespace kdb;
18 :
19 138 : ShellGetCommand::ShellGetCommand ()
20 : {
21 138 : }
22 :
23 60 : int ShellGetCommand::execute (Cmdline const & cl)
24 : {
25 120 : if (cl.arguments.size () != 2) throw invalid_argument ("Need two arguments");
26 :
27 180 : std::string default_value = cl.arguments[1];
28 :
29 : try
30 : {
31 120 : kdb::KDB kdb;
32 120 : KeySet conf;
33 120 : Key x = cl.createKey (0);
34 :
35 60 : kdb.get (conf, x);
36 120 : Key k = conf.lookup (x);
37 :
38 60 : if (!k)
39 : {
40 22 : throw invalid_argument ("Did not find key");
41 : }
42 :
43 114 : cout << k.getString ();
44 : }
45 44 : catch (...)
46 : {
47 22 : std::cout << default_value;
48 : }
49 :
50 120 : return 0;
51 : }
52 :
53 138 : ShellGetCommand::~ShellGetCommand ()
54 : {
55 7302 : }
|