diff options
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.cpp | 39 | ||||
-rw-r--r-- | akonadi2_cli/modules/help/help.h | 37 |
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" | 26 | namespace CoreSyntax |
27 | { | ||
27 | 28 | ||
28 | namespace CLI | 29 | Module::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 | ||
31 | Help::Help() | 37 | bool 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 | ||
37 | bool Help::showHelp(const QStringList &commands, State &) | 43 | bool 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 | ||
24 | namespace CLI | 24 | namespace CoreSyntax |
25 | { | 25 | { |
26 | 26 | Module::SyntaxList syntax(); | |
27 | class Exit : public Module | 27 | bool exit(const QStringList &commands, State &state); |
28 | { | 28 | bool showHelp(const QStringList &commands, State &); |
29 | public: | 29 | } |
30 | Exit(); | ||
31 | |||
32 | private: | ||
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 | |||
24 | namespace CLI | ||
25 | { | ||
26 | |||
27 | Exit::Exit() | ||
28 | { | ||
29 | setSyntax(Syntax("exit", &Exit::exit, QObject::tr("Exits the application. Ctrl-d also works!"))); | ||
30 | } | ||
31 | |||
32 | bool 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 | |||
24 | namespace CLI | ||
25 | { | ||
26 | |||
27 | class Help : public Module | ||
28 | { | ||
29 | public: | ||
30 | Help(); | ||
31 | |||
32 | private: | ||
33 | static bool showHelp(const QStringList &commands, State &state); | ||
34 | }; | ||
35 | |||
36 | } // namespace CLI | ||
37 | |||