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 <globalumount.hpp>
10 :
11 : #include <cmdline.hpp>
12 : #include <kdb.hpp>
13 :
14 : #include <algorithm>
15 : #include <iostream>
16 :
17 : using namespace std;
18 : using namespace kdb;
19 :
20 159 : GlobalUmountCommand::GlobalUmountCommand ()
21 : {
22 159 : }
23 :
24 3 : int GlobalUmountCommand::execute (Cmdline const & cl)
25 : {
26 6 : if (cl.arguments.size () != 1) throw invalid_argument ("1 argument required");
27 :
28 6 : KeySet conf;
29 : // they are all mounted in that array
30 6 : Key parentKey ("system/elektra/globalplugins/postcommit/user/plugins/", KEY_END);
31 3 : kdb.get (conf, parentKey);
32 3 : printWarnings (cerr, parentKey, cl.verbose, cl.debug);
33 :
34 9 : const string name = cl.arguments[0];
35 : auto it =
36 87 : find_if (conf.begin (), conf.end (), [&](Key key) { return key.isDirectBelow (parentKey) && key.get<string> () == name; });
37 :
38 6 : if (it == conf.end ())
39 : {
40 0 : cerr << "Global Plugin " << name << " does not exist" << endl;
41 : return 1;
42 : }
43 :
44 12 : conf.cut (*it);
45 3 : kdb.set (conf, parentKey);
46 :
47 : return 0;
48 : }
49 :
50 318 : GlobalUmountCommand::~GlobalUmountCommand ()
51 : {
52 7323 : }
|