/
export.cpp
73 lines (55 loc) · 1.29 KB
/
export.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @file
*
* @brief
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
#include <export.hpp>
#include <cmdline.hpp>
#include <kdb.hpp>
#include <modules.hpp>
#include <toolexcept.hpp>
#include <iostream>
using namespace std;
using namespace kdb;
using namespace kdb::tools;
ExportCommand::ExportCommand ()
{
}
int ExportCommand::execute (Cmdline const & cl)
{
size_t argc = cl.arguments.size ();
if (argc != 1 && argc != 2 && argc != 3)
{
throw invalid_argument ("need 1 to 3 arguments");
}
Key root = cl.createKey (0);
kdb.get (ks, root);
printWarnings (cerr, root, cl.verbose, cl.debug);
KeySet part (ks.cut (root));
if (cl.withoutElektra)
{
Key systemElektra ("system/elektra", KEY_END);
part.cut (systemElektra);
}
string format = cl.format;
if (argc > 1) format = cl.arguments[1];
#ifdef _WIN32
string file = "CON";
#else
string file = "/dev/stdout";
#endif
if (argc > 2 && cl.arguments[2] != "-") file = cl.arguments[2];
Modules modules;
PluginPtr plugin = modules.load (format, cl.getPluginsConfig ());
Key errorKey (root);
errorKey.setString (file);
plugin->set (part, errorKey);
printWarnings (cerr, errorKey, cl.verbose, cl.debug);
printError (cerr, errorKey, cl.verbose, cl.debug);
return 0;
}
ExportCommand::~ExportCommand ()
{
}