diff options
author | Aaron Seigo <aseigo@kde.org> | 2014-12-10 08:49:45 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2014-12-11 01:02:32 +0100 |
commit | 558ca7f17ae4f6df48b999e98c4004a49549cd79 (patch) | |
tree | fd5dfb6a5dbe1768ce4a85fd3b804cf28bf366f2 /tests/hawd/modules/print.cpp | |
parent | 49400da50b9095ea8b935135877ed76163552c7f (diff) | |
download | sink-558ca7f17ae4f6df48b999e98c4004a49549cd79.tar.gz sink-558ca7f17ae4f6df48b999e98c4004a49549cd79.zip |
print command
Diffstat (limited to 'tests/hawd/modules/print.cpp')
-rw-r--r-- | tests/hawd/modules/print.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/hawd/modules/print.cpp b/tests/hawd/modules/print.cpp new file mode 100644 index 0000000..1f59c4e --- /dev/null +++ b/tests/hawd/modules/print.cpp | |||
@@ -0,0 +1,74 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #include "print.h" | ||
21 | |||
22 | #include "../datasetdefinition.h" | ||
23 | #include "../dataset.h" | ||
24 | |||
25 | #include <QDir> | ||
26 | #include <QObject> | ||
27 | |||
28 | #include <iostream> | ||
29 | |||
30 | namespace HAWD | ||
31 | { | ||
32 | |||
33 | Print::Print() | ||
34 | : Module() | ||
35 | { | ||
36 | Syntax top("print", &Print::print); | ||
37 | setSyntax(top); | ||
38 | setDescription(QObject::tr("Prints a table from a dataset; you can provide a list of rows to output")); | ||
39 | } | ||
40 | |||
41 | bool Print::print(const QStringList &commands, State &state) | ||
42 | { | ||
43 | if (commands.isEmpty()) { | ||
44 | std::cout << QObject::tr("print requires a dataset to be named").toStdString() << std::endl; | ||
45 | return true; | ||
46 | } | ||
47 | |||
48 | const QString datasetName = commands.first(); | ||
49 | |||
50 | QDir project(state.projectPath()); | ||
51 | Dataset dataset(datasetName, state); | ||
52 | |||
53 | if (!dataset.isValid()) { | ||
54 | std::cout << QObject::tr("The dataset %1 could not be loaded; try checking it with the check command").arg(datasetName).toStdString() << std::endl; | ||
55 | return true; | ||
56 | } | ||
57 | |||
58 | QStringList cols; | ||
59 | if (commands.size() > 1) { | ||
60 | cols = commands; | ||
61 | cols.removeFirst(); | ||
62 | } | ||
63 | |||
64 | std::cout << dataset.tableHeaders(cols).toStdString() << std::endl; | ||
65 | |||
66 | dataset.eachRow( | ||
67 | [cols](const Dataset::Row &row) { | ||
68 | std::cout << row.toString(cols).toStdString() << std::endl; | ||
69 | }); | ||
70 | return true; | ||
71 | } | ||
72 | |||
73 | } // namespace HAWD | ||
74 | |||