summaryrefslogtreecommitdiffstats
path: root/akonadi2_cli/modules
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2015-12-23 11:43:37 +0100
committerAaron Seigo <aseigo@kde.org>2015-12-23 11:43:37 +0100
commit071f4ef0122a8bfceeda9a10b41e85ad9a34a28d (patch)
treee5d1cb7efcac5eb16f4848619ff06142906b6cea /akonadi2_cli/modules
parent255d73af197faf8437343abc10bd98cca2057a1e (diff)
downloadsink-071f4ef0122a8bfceeda9a10b41e85ad9a34a28d.tar.gz
sink-071f4ef0122a8bfceeda9a10b41e85ad9a34a28d.zip
vastly simplify by getting rid of Module as a base class
just a move slightly more towards functional
Diffstat (limited to 'akonadi2_cli/modules')
-rw-r--r--akonadi2_cli/modules/core_syntax.cpp (renamed from akonadi2_cli/modules/help/help.cpp)33
-rw-r--r--akonadi2_cli/modules/core_syntax.h (renamed from akonadi2_cli/modules/exit/exit.h)17
-rw-r--r--akonadi2_cli/modules/exit/exit.cpp39
-rw-r--r--akonadi2_cli/modules/help/help.h37
4 files changed, 24 insertions, 102 deletions
diff --git a/akonadi2_cli/modules/help/help.cpp b/akonadi2_cli/modules/core_syntax.cpp
index aaff6fb..8324c31 100644
--- a/akonadi2_cli/modules/help/help.cpp
+++ b/akonadi2_cli/modules/core_syntax.cpp
@@ -17,39 +17,45 @@
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */ 18 */
19 19
20#include "help.h" 20#include "core_syntax.h"
21 21
22#include <QObject> 22#include <QObject> // tr()
23#include <QSet> 23#include <QSet>
24#include <QTextStream> 24#include <QTextStream>
25 25
26#include "module.h" 26namespace CoreSyntax
27{
27 28
28namespace CLI 29Module::SyntaxList syntax()
29{ 30{
31 Module::SyntaxList syntax;
32 syntax << Module::Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit);
33 syntax << Module::Syntax(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp);
34 return syntax;
35}
30 36
31Help::Help() 37bool exit(const QStringList &, State &)
32{ 38{
33 Syntax topLevel = Syntax(QObject::tr("help"), &Help::showHelp, QObject::tr("Print command information: help [command]")); 39 ::exit(0);
34 setSyntax(topLevel); 40 return true;
35} 41}
36 42
37bool Help::showHelp(const QStringList &commands, State &) 43bool showHelp(const QStringList &commands, State &)
38{ 44{
39 Module::Command command = Module::match(commands); 45 Module::Command command = Module::self()->match(commands);
40 QTextStream stream(stdout); 46 QTextStream stream(stdout);
41 if (commands.isEmpty()) { 47 if (commands.isEmpty()) {
42 stream << QObject::tr("Welcome to the Akonadi2 command line tool!") << "\n"; 48 stream << QObject::tr("Welcome to the Akonadi2 command line tool!") << "\n";
43 stream << QObject::tr("Top-level commands:") << "\n"; 49 stream << QObject::tr("Top-level commands:") << "\n";
44 QSet<QString> sorted; 50 QSet<QString> sorted;
45 for (auto module: Module::modules()) { 51 for (auto syntax: Module::self()->syntax()) {
46 sorted.insert(module.syntax().keyword); 52 sorted.insert(syntax.keyword);
47 } 53 }
48 54
49 for (auto keyword: sorted) { 55 for (auto keyword: sorted) {
50 stream << "\t" << keyword << "\n"; 56 stream << "\t" << keyword << "\n";
51 } 57 }
52 } else if (const Syntax *syntax = command.first) { 58 } else if (const Module::Syntax *syntax = command.first) {
53 //TODO: get parent! 59 //TODO: get parent!
54 stream << QObject::tr("Command `%1`").arg(syntax->keyword); 60 stream << QObject::tr("Command `%1`").arg(syntax->keyword);
55 61
@@ -72,9 +78,8 @@ bool Help::showHelp(const QStringList &commands, State &)
72 } else { 78 } else {
73 stream << "Unknown command: " << commands.join(" ") << "\n"; 79 stream << "Unknown command: " << commands.join(" ") << "\n";
74 } 80 }
75
76 return true; 81 return true;
77} 82}
78 83
79} // namespace CLI 84} // namespace CoreSyntax
80 85
diff --git a/akonadi2_cli/modules/exit/exit.h b/akonadi2_cli/modules/core_syntax.h
index 5ed4174..beb8528 100644
--- a/akonadi2_cli/modules/exit/exit.h
+++ b/akonadi2_cli/modules/core_syntax.h
@@ -21,17 +21,10 @@
21 21
22#include "module.h" 22#include "module.h"
23 23
24namespace CLI 24namespace CoreSyntax
25{ 25{
26 26 Module::SyntaxList syntax();
27class Exit : public Module 27 bool exit(const QStringList &commands, State &state);
28{ 28 bool showHelp(const QStringList &commands, State &);
29public: 29}
30 Exit();
31
32private:
33 static bool exit(const QStringList &commands, State &state);
34};
35
36} // namespace CLI
37 30
diff --git a/akonadi2_cli/modules/exit/exit.cpp b/akonadi2_cli/modules/exit/exit.cpp
deleted file mode 100644
index 64828be..0000000
--- a/akonadi2_cli/modules/exit/exit.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
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 "exit.h"
21
22#include <QObject>
23
24namespace CLI
25{
26
27Exit::Exit()
28{
29 setSyntax(Syntax("exit", &Exit::exit, QObject::tr("Exits the application. Ctrl-d also works!")));
30}
31
32bool Exit::exit(const QStringList &, State &)
33{
34 ::exit(0);
35 return true;
36}
37
38} // namespace CLI
39
diff --git a/akonadi2_cli/modules/help/help.h b/akonadi2_cli/modules/help/help.h
deleted file mode 100644
index df1cfc2..0000000
--- a/akonadi2_cli/modules/help/help.h
+++ /dev/null
@@ -1,37 +0,0 @@
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 CLI
25{
26
27class Help : public Module
28{
29public:
30 Help();
31
32private:
33 static bool showHelp(const QStringList &commands, State &state);
34};
35
36} // namespace CLI
37