summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/hawd/CMakeLists.txt1
-rw-r--r--tests/hawd/module.cpp3
-rw-r--r--tests/hawd/modules/print.cpp74
-rw-r--r--tests/hawd/modules/print.h37
4 files changed, 114 insertions, 1 deletions
diff --git a/tests/hawd/CMakeLists.txt b/tests/hawd/CMakeLists.txt
index e15589a..413c86b 100644
--- a/tests/hawd/CMakeLists.txt
+++ b/tests/hawd/CMakeLists.txt
@@ -13,6 +13,7 @@ set(SRCS
13 module.cpp 13 module.cpp
14 modules/list.cpp 14 modules/list.cpp
15 modules/check.cpp 15 modules/check.cpp
16 modules/print.cpp
16) 17)
17 18
18add_library(libhawd ${lib_SRCS}) 19add_library(libhawd ${lib_SRCS})
diff --git a/tests/hawd/module.cpp b/tests/hawd/module.cpp
index eb45def..7753b44 100644
--- a/tests/hawd/module.cpp
+++ b/tests/hawd/module.cpp
@@ -21,6 +21,7 @@
21 21
22#include "modules/list.h" 22#include "modules/list.h"
23#include "modules/check.h" 23#include "modules/check.h"
24#include "modules/print.h"
24 25
25#include <QCoreApplication> 26#include <QCoreApplication>
26 27
@@ -51,7 +52,7 @@ void Module::loadModules()
51 addModule(List()); 52 addModule(List());
52 addModule(Check()); 53 addModule(Check());
53 addModule(CheckAll()); 54 addModule(CheckAll());
54// addModule(Print()); 55 addModule(Print());
55// addModule(Annotate()); 56// addModule(Annotate());
56// addModule(Remove()); 57// addModule(Remove());
57} 58}
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
30namespace HAWD
31{
32
33Print::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
41bool 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
diff --git a/tests/hawd/modules/print.h b/tests/hawd/modules/print.h
new file mode 100644
index 0000000..eb03636
--- /dev/null
+++ b/tests/hawd/modules/print.h
@@ -0,0 +1,37 @@
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#pragma once
21
22#include "module.h"
23
24namespace HAWD
25{
26
27class Print : public Module
28{
29public:
30 Print();
31
32private:
33 static bool print(const QStringList &commands, State &state);
34};
35
36} // namespace HAWD
37