From 323f60b25f0872ddee04f52aec374b741dbf9d17 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sun, 7 Dec 2014 16:06:23 +0100 Subject: How Are We Doing (hawd) framework --- tests/hawd/modules/list.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/hawd/modules/list.cpp (limited to 'tests/hawd/modules/list.cpp') diff --git a/tests/hawd/modules/list.cpp b/tests/hawd/modules/list.cpp new file mode 100644 index 0000000..3310217 --- /dev/null +++ b/tests/hawd/modules/list.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2014 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "list.h" + +#include "../datasetdefinition.h" + +#include +#include +#include + +#include + +namespace HAWD +{ + +List::List() + : Module() +{ + Syntax top("list", &List::list); + //top.children << Syntax("create", &List::create); + setSyntax(top); +} + +bool List::list(const QStringList &commands, State &state) +{ + QDir project(state.projectPath()); + + if (commands.isEmpty()) { + project.setFilter(QDir::Files | QDir::Readable | QDir::NoDotAndDotDot | QDir::NoSymLinks); + const QStringList entryList = project.entryList(); + + if (entryList.isEmpty()) { + std::cout << QObject::tr("No data sets in this project").toStdString() << std::endl; + } else { + std::cout << QObject::tr("Data sets in this project:").toStdString() << std::endl; + for (const QString &file: project.entryList()) { + std::cout << '\t' << file.toStdString() << std::endl; + } + } + } else { + for (const QString &file: commands) { + DatasetDefinition dataset(project.absoluteFilePath(file)); + if (dataset.isValid()) { + DatasetDefinition dataset(project.absoluteFilePath(file)); + std::cout << '\t' << QObject::tr("Dataset: %1").arg(dataset.name()).toStdString() << std::endl; + QHashIterator it(dataset.columns()); + while (it.hasNext()) { + it.next(); + std::cout << "\t\t" << it.value().typeString().toStdString() << ' ' << it.key().toStdString() << std::endl; + } + + } else { + std::cout << QObject::tr("Invalid or non-existent dataset definition at %1").arg(project.absoluteFilePath(file)).toStdString() << std::endl; + } + } + } + + return true; +} + +} // namespace HAWD + -- cgit v1.2.3