Commit 86cfc1c8 authored by nicolas's avatar nicolas

feat(Cli): method syntax auto generated when --cli-help

parent 0721a22b
...@@ -431,43 +431,23 @@ Server url not configured.</translation> ...@@ -431,43 +431,23 @@ Server url not configured.</translation>
</message> </message>
<message> <message>
<source>showFunctionDescription</source> <source>showFunctionDescription</source>
<translation>Shows the main window of the application.</translation> <translation>Show the main window of the application.</translation>
</message>
<message>
<source>showCliDescription</source>
<translation>&quot;show&quot;</translation>
</message> </message>
<message> <message>
<source>callFunctionDescription</source> <source>callFunctionDescription</source>
<translation>Initiates a call towards &lt;sip-address&gt;.</translation> <translation>Initiate a call to the sip-address.</translation>
</message>
<message>
<source>callCliDescription</source>
<translation>&quot;call sip-address=&lt;sip-address&gt;&quot;</translation>
</message> </message>
<message> <message>
<source>initiateConferenceFunctionDescription</source> <source>initiateConferenceFunctionDescription</source>
<translation>Initiates a conference of id &lt;id&gt;.</translation> <translation>Initiate a conference.</translation>
</message>
<message>
<source>initiateConferenceCliDescription</source>
<translation>&quot;initiate-conference sip-address=&lt;my sip-address&gt; conference-id=&lt;id&gt;&quot;</translation>
</message> </message>
<message> <message>
<source>joinConferenceFunctionDescription</source> <source>joinConferenceFunctionDescription</source>
<translation>Joins the n°&lt;id&gt; conference hosted by the &lt;host sip-address&gt; as &lt;name&gt;. If you are connected to a proxy config, see join-conference-as.</translation> <translation>Join the conference hosted by the sip-address as display-name. If you are connected to a proxy config, see join-conference-as.</translation>
</message>
<message>
<source>joinConferenceCliDescription</source>
<translation>&quot;join-conference sip-address=&lt;host sip-address&gt; conference-id=&lt;id&gt; display-name=&lt;name&gt;&quot;</translation>
</message> </message>
<message> <message>
<source>joinConferenceAsFunctionDescription</source> <source>joinConferenceAsFunctionDescription</source>
<translation>Joins the n°&lt;id&gt; conference hosted by the &lt;host sip-address&gt; as&lt;my sip-address&gt;. If you are not connected to a proxy-config, see join-conference.</translation> <translation>Join the conference hosted by the sip-address as with the guest-sip-address. If you are not connected to a proxy-config, see join-conference.</translation>
</message>
<message>
<source>joinConferenceAsCliDescription</source>
<translation>&quot;join-conference-as sip-address=&lt;host sip-address&gt; conference-id=&lt;id&gt; guest-sip-address=&lt;my sip-address&gt;&quot;</translation>
</message> </message>
</context> </context>
<context> <context>
......
...@@ -433,41 +433,21 @@ Url du serveur non configurée.</translation> ...@@ -433,41 +433,21 @@ Url du serveur non configurée.</translation>
<source>showFunctionDescription</source> <source>showFunctionDescription</source>
<translation>Affiche la fenêtre principale de l&apos;application.</translation> <translation>Affiche la fenêtre principale de l&apos;application.</translation>
</message> </message>
<message>
<source>showCliDescription</source>
<translation>&quot;show&quot;</translation>
</message>
<message> <message>
<source>callFunctionDescription</source> <source>callFunctionDescription</source>
<translation>Initie un appel vers &lt;sip-address&gt;.</translation> <translation>Initie un appel vers la sip-address.</translation>
</message>
<message>
<source>callCliDescription</source>
<translation>&quot;call sip-address=&lt;sip-address&gt;&quot;</translation>
</message> </message>
<message> <message>
<source>initiateConferenceFunctionDescription</source> <source>initiateConferenceFunctionDescription</source>
<translation>Initie une conférence d&apos;id &lt;id&gt;.</translation> <translation>Initie une conférence.</translation>
</message>
<message>
<source>initiateConferenceCliDescription</source>
<translation>&quot;initiate-conference sip-address=&lt;ma sip-address&gt; conference-id=&lt;id&gt;&quot;</translation>
</message> </message>
<message> <message>
<source>joinConferenceFunctionDescription</source> <source>joinConferenceFunctionDescription</source>
<translation>Rejoint la conférence n°&lt;id&gt; hébergée par la &lt;sip-address de l&apos;host&gt; en tant que &lt;nom&gt;. Si vous êtes connecté à une proxy config, voir join-conference-as.</translation> <translation>Rejoint la conférence hébergée par la sip-address avec un display-name. Si vous êtes connecté à une proxy config, voir join-conference-as.</translation>
</message>
<message>
<source>joinConferenceCliDescription</source>
<translation>&quot;join-conference sip-address=&lt;sip-address de l&apos;host&gt; conference-id=&lt;id&gt; display-name=&lt;nom&gt;&quot;</translation>
</message> </message>
<message> <message>
<source>joinConferenceAsFunctionDescription</source> <source>joinConferenceAsFunctionDescription</source>
<translation>Rejoint la conférence n°&lt;id&gt; hébergée par la &lt;sip-address de l&apos;host&gt; en tant que &lt;ma sip-address&gt;. Si vous n&apos;êtes pas connecté à une proxy-config, voir join-conference.</translation> <translation>Rejoint la conférence hébergée par la sip-address avec la guest-sip-address. Si vous n&apos;êtes pas connecté à une proxy-config, voir join-conference.</translation>
</message>
<message>
<source>joinConferenceAsCliDescription</source>
<translation>&quot;join-conference-as sip-address=&lt;sip-address de l&apos;host&gt; conference-id=&lt;id&gt; guest-sip-address=&lt;ma sip-address&gt;&quot;</translation>
</message> </message>
</context> </context>
<context> <context>
......
...@@ -219,13 +219,11 @@ static string multilineIndent (const QString &str, int indentationNumber = 0) { ...@@ -219,13 +219,11 @@ static string multilineIndent (const QString &str, int indentationNumber = 0) {
Cli::Command::Command ( Cli::Command::Command (
const QString &functionName, const QString &functionName,
const char *functionDescription, const char *functionDescription,
const char *cliDescription,
Cli::Function function, Cli::Function function,
const QHash<QString, Cli::Argument> &argsScheme const QHash<QString, Cli::Argument> &argsScheme
) : ) :
mFunctionName(functionName), mFunctionName(functionName),
mFunctionDescription(functionDescription), mFunctionDescription(functionDescription),
mCliDescription(cliDescription),
mFunction(function), mFunction(function),
mArgsScheme(argsScheme) {} mArgsScheme(argsScheme) {}
...@@ -275,6 +273,30 @@ void Cli::Command::executeUri (const shared_ptr<linphone::Address> &address) con ...@@ -275,6 +273,30 @@ void Cli::Command::executeUri (const shared_ptr<linphone::Address> &address) con
execute(args); execute(args);
} }
QString Cli::Command::getFunctionSyntax () const {
QString functionSyntax;
functionSyntax += QStringLiteral("\"");
functionSyntax += mFunctionName;
for (auto &argName : mArgsScheme.keys()){
functionSyntax += QStringLiteral(" ");
functionSyntax += mArgsScheme[argName].isOptional ? QStringLiteral("[") : QStringLiteral("");
functionSyntax += argName;
functionSyntax += QStringLiteral("=<");
switch (mArgsScheme[argName].type) {
case STRING :
functionSyntax += QStringLiteral("str");
break;
default:
functionSyntax += QStringLiteral("value");
break;
}
functionSyntax += QString(">");
functionSyntax += mArgsScheme[argName].isOptional ? QStringLiteral("]") : QStringLiteral("");
}
functionSyntax += QStringLiteral("\"");
return functionSyntax;
}
// ============================================================================= // =============================================================================
// FIXME: Do not accept args without value like: cmd toto. // FIXME: Do not accept args without value like: cmd toto.
...@@ -283,17 +305,17 @@ QRegExp Cli::mRegExpArgs("(?:(?:([\\w-]+)\\s*)=\\s*(?:\"([^\"\\\\]*(?:\\\\.[^\"\ ...@@ -283,17 +305,17 @@ QRegExp Cli::mRegExpArgs("(?:(?:([\\w-]+)\\s*)=\\s*(?:\"([^\"\\\\]*(?:\\\\.[^\"\
QRegExp Cli::mRegExpFunctionName("^\\s*([a-z-]+)\\s*"); QRegExp Cli::mRegExpFunctionName("^\\s*([a-z-]+)\\s*");
QMap<QString, Cli::Command> Cli::mCommands = { QMap<QString, Cli::Command> Cli::mCommands = {
createCommand("show", QT_TR_NOOP("showFunctionDescription"), QT_TR_NOOP("showCliDescription"), ::cliShow), createCommand("show", QT_TR_NOOP("showFunctionDescription"), ::cliShow),
createCommand("call", QT_TR_NOOP("callFunctionDescription"), QT_TR_NOOP("callCliDescription"), ::cliCall, { createCommand("call", QT_TR_NOOP("callFunctionDescription"), ::cliCall, {
{ "sip-address", {} } { "sip-address", {} }
}), }),
createCommand("initiate-conference", QT_TR_NOOP("initiateConferenceFunctionDescription"), QT_TR_NOOP("initiateConferenceCliDescription"), ::cliInitiateConference, { createCommand("initiate-conference", QT_TR_NOOP("initiateConferenceFunctionDescription"), ::cliInitiateConference, {
{ "sip-address", {} }, { "conference-id", {} } { "sip-address", {} }, { "conference-id", {} }
}), }),
createCommand("join-conference", QT_TR_NOOP("joinConferenceFunctionDescription"), QT_TR_NOOP("joinConferenceCliDescription"), ::cliJoinConference, { createCommand("join-conference", QT_TR_NOOP("joinConferenceFunctionDescription"), ::cliJoinConference, {
{ "sip-address", {} }, { "conference-id", {} }, { "display-name", {} } { "sip-address", {} }, { "conference-id", {} }, { "display-name", {} }
}), }),
createCommand("join-conference-as", QT_TR_NOOP("joinConferenceAsFunctionDescription"), QT_TR_NOOP("joinConferenceAsCliDescription"), ::cliJoinConferenceAs, { createCommand("join-conference-as", QT_TR_NOOP("joinConferenceAsFunctionDescription"), ::cliJoinConferenceAs, {
{ "sip-address", {} }, { "conference-id", {} }, { "guest-sip-address", {} } { "sip-address", {} }, { "conference-id", {} }, { "guest-sip-address", {} }
}) })
}; };
...@@ -354,7 +376,7 @@ void Cli::showHelp () { ...@@ -354,7 +376,7 @@ void Cli::showHelp () {
multilineIndent(tr("commandsName")) << endl; multilineIndent(tr("commandsName")) << endl;
for (const auto &method : mCommands.keys()) for (const auto &method : mCommands.keys())
cout << multilineIndent(tr(mCommands[method].getCliDescription()), 1) << cout << multilineIndent(mCommands[method].getFunctionSyntax(), 1) <<
multilineIndent(tr(mCommands[method].getFunctionDescription()), 2) << multilineIndent(tr(mCommands[method].getFunctionDescription()), 2) <<
endl; endl;
} }
...@@ -364,11 +386,10 @@ void Cli::showHelp () { ...@@ -364,11 +386,10 @@ void Cli::showHelp () {
pair<QString, Cli::Command> Cli::createCommand ( pair<QString, Cli::Command> Cli::createCommand (
const QString &functionName, const QString &functionName,
const char *functionDescription, const char *functionDescription,
const char *cliDescription,
Function function, Function function,
const QHash<QString, Argument> &argsScheme const QHash<QString, Argument> &argsScheme
) { ) {
return { functionName, Cli::Command(functionName, functionDescription, cliDescription, function, argsScheme) }; return { functionName, Cli::Command(functionName, functionDescription, function, argsScheme) };
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -60,7 +60,6 @@ class Cli : public QObject { ...@@ -60,7 +60,6 @@ class Cli : public QObject {
Command ( Command (
const QString &functionName, const QString &functionName,
const char *functionDescription, const char *functionDescription,
const char *cliDescription,
Function function, Function function,
const QHash<QString, Argument> &argsScheme const QHash<QString, Argument> &argsScheme
); );
...@@ -72,14 +71,11 @@ class Cli : public QObject { ...@@ -72,14 +71,11 @@ class Cli : public QObject {
return mFunctionDescription; return mFunctionDescription;
} }
const char *getCliDescription () const { QString getFunctionSyntax () const ;
return mCliDescription;
}
private: private:
QString mFunctionName; QString mFunctionName;
const char *mFunctionDescription; const char *mFunctionDescription;
const char *mCliDescription;
Function mFunction = nullptr; Function mFunction = nullptr;
QHash<QString, Argument> mArgsScheme; QHash<QString, Argument> mArgsScheme;
}; };
...@@ -103,7 +99,6 @@ private: ...@@ -103,7 +99,6 @@ private:
static std::pair<QString, Command> createCommand ( static std::pair<QString, Command> createCommand (
const QString &functionName, const QString &functionName,
const char *functionDescription, const char *functionDescription,
const char *cliDescription,
Function function, Function function,
const QHash<QString, Argument> &argsScheme = QHash<QString, Argument>() const QHash<QString, Argument> &argsScheme = QHash<QString, Argument>()
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment