diff options
author | Aaron Seigo <aseigo@kde.org> | 2015-12-23 17:02:59 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2015-12-23 17:02:59 +0100 |
commit | e995699ad88e6c6f1980d11c45a544c79993ccb5 (patch) | |
tree | d928803b5d31b62343ee24aed7c41427941d8e0c | |
parent | 72f52fb148380feb018faa9a94a8ad54bb93635f (diff) | |
download | sink-e995699ad88e6c6f1980d11c45a544c79993ccb5.tar.gz sink-e995699ad88e6c6f1980d11c45a544c79993ccb5.zip |
set/get syntax, currently just for debug level
-rw-r--r-- | akonadi2_cli/syntax_modules/core_syntax.cpp | 35 | ||||
-rw-r--r-- | akonadi2_cli/syntax_modules/core_syntax.h | 4 |
2 files changed, 38 insertions, 1 deletions
diff --git a/akonadi2_cli/syntax_modules/core_syntax.cpp b/akonadi2_cli/syntax_modules/core_syntax.cpp index f71c1d6..f9cd622 100644 --- a/akonadi2_cli/syntax_modules/core_syntax.cpp +++ b/akonadi2_cli/syntax_modules/core_syntax.cpp | |||
@@ -19,6 +19,7 @@ | |||
19 | 19 | ||
20 | #include "core_syntax.h" | 20 | #include "core_syntax.h" |
21 | 21 | ||
22 | #include <QDebug> | ||
22 | #include <QObject> // tr() | 23 | #include <QObject> // tr() |
23 | #include <QSet> | 24 | #include <QSet> |
24 | #include <QTextStream> | 25 | #include <QTextStream> |
@@ -31,6 +32,15 @@ SyntaxTree::SyntaxList syntax() | |||
31 | SyntaxTree::SyntaxList syntax; | 32 | SyntaxTree::SyntaxList syntax; |
32 | syntax << SyntaxTree::Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); | 33 | syntax << SyntaxTree::Syntax("exit", QObject::tr("Exits the application. Ctrl-d also works!"), &CoreSyntax::exit); |
33 | syntax << SyntaxTree::Syntax(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); | 34 | syntax << SyntaxTree::Syntax(QObject::tr("help"), QObject::tr("Print command information: help [command]"), &CoreSyntax::showHelp); |
35 | |||
36 | SyntaxTree::Syntax set(QObject::tr("set"), QObject::tr("Sets settings for the session")); | ||
37 | set.children << SyntaxTree::Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::setDebugLevel); | ||
38 | syntax << set; | ||
39 | |||
40 | SyntaxTree::Syntax get(QObject::tr("get"), QObject::tr("Gets settings for the session")); | ||
41 | get.children << SyntaxTree::Syntax(QObject::tr("debug"), QObject::tr("Set the debug level from 0 to 6"), &CoreSyntax::printDebugLevel); | ||
42 | syntax << get; | ||
43 | |||
34 | return syntax; | 44 | return syntax; |
35 | } | 45 | } |
36 | 46 | ||
@@ -82,5 +92,30 @@ bool showHelp(const QStringList &commands, State &state) | |||
82 | return true; | 92 | return true; |
83 | } | 93 | } |
84 | 94 | ||
95 | bool setDebugLevel(const QStringList &commands, State &state) | ||
96 | { | ||
97 | if (commands.count() != 1) { | ||
98 | state.printError(QObject::tr("Wrong number of arguments; expected 1 got %1").arg(commands.count())); | ||
99 | return false; | ||
100 | } | ||
101 | |||
102 | bool ok = false; | ||
103 | int level = commands[0].toUInt(&ok); | ||
104 | |||
105 | if (!ok) { | ||
106 | state.printError(QObject::tr("Expected a number between 0 and 6, got %1").arg(commands[0])); | ||
107 | return false; | ||
108 | } | ||
109 | |||
110 | state.setDebugLevel(level); | ||
111 | return true; | ||
112 | } | ||
113 | |||
114 | bool printDebugLevel(const QStringList &commands, State &state) | ||
115 | { | ||
116 | state.printLine(QString::number(state.debugLevel())); | ||
117 | return true; | ||
118 | } | ||
119 | |||
85 | } // namespace CoreSyntax | 120 | } // namespace CoreSyntax |
86 | 121 | ||
diff --git a/akonadi2_cli/syntax_modules/core_syntax.h b/akonadi2_cli/syntax_modules/core_syntax.h index 0db6661..4afd69d 100644 --- a/akonadi2_cli/syntax_modules/core_syntax.h +++ b/akonadi2_cli/syntax_modules/core_syntax.h | |||
@@ -25,6 +25,8 @@ namespace CoreSyntax | |||
25 | { | 25 | { |
26 | SyntaxTree::SyntaxList syntax(); | 26 | SyntaxTree::SyntaxList syntax(); |
27 | bool exit(const QStringList &commands, State &state); | 27 | bool exit(const QStringList &commands, State &state); |
28 | bool showHelp(const QStringList &commands, State &); | 28 | bool showHelp(const QStringList &commands, State &state); |
29 | bool setDebugLevel(const QStringList &commands, State &state); | ||
30 | bool printDebugLevel(const QStringList &commands, State &state); | ||
29 | } | 31 | } |
30 | 32 | ||