From 86cfc1c81648bc9176e8744bb3723f2f6a582842 Mon Sep 17 00:00:00 2001 From: nicolas Date: Wed, 6 Sep 2017 15:59:08 +0200 Subject: [PATCH] feat(Cli): method syntax auto generated when --cli-help --- assets/languages/en.ts | 30 +++++------------------------- assets/languages/fr.ts | 28 ++++------------------------ src/app/cli/Cli.cpp | 41 +++++++++++++++++++++++++++++++---------- src/app/cli/Cli.hpp | 7 +------ 4 files changed, 41 insertions(+), 65 deletions(-) diff --git a/assets/languages/en.ts b/assets/languages/en.ts index a7df11924..9578d6b5d 100644 --- a/assets/languages/en.ts +++ b/assets/languages/en.ts @@ -431,43 +431,23 @@ Server url not configured. showFunctionDescription - Shows the main window of the application. - - - showCliDescription - "show" + Show the main window of the application. callFunctionDescription - Initiates a call towards <sip-address>. - - - callCliDescription - "call sip-address=<sip-address>" + Initiate a call to the sip-address. initiateConferenceFunctionDescription - Initiates a conference of id <id>. - - - initiateConferenceCliDescription - "initiate-conference sip-address=<my sip-address> conference-id=<id>" + Initiate a conference. joinConferenceFunctionDescription - Joins the n°<id> conference hosted by the <host sip-address> as <name>. If you are connected to a proxy config, see join-conference-as. - - - joinConferenceCliDescription - "join-conference sip-address=<host sip-address> conference-id=<id> display-name=<name>" + Join the conference hosted by the sip-address as display-name. If you are connected to a proxy config, see join-conference-as. joinConferenceAsFunctionDescription - Joins the n°<id> conference hosted by the <host sip-address> as<my sip-address>. If you are not connected to a proxy-config, see join-conference. - - - joinConferenceAsCliDescription - "join-conference-as sip-address=<host sip-address> conference-id=<id> guest-sip-address=<my sip-address>" + 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. diff --git a/assets/languages/fr.ts b/assets/languages/fr.ts index 8d70c1910..e9a93a65c 100644 --- a/assets/languages/fr.ts +++ b/assets/languages/fr.ts @@ -433,41 +433,21 @@ Url du serveur non configurée. showFunctionDescription Affiche la fenêtre principale de l'application. - - showCliDescription - "show" - callFunctionDescription - Initie un appel vers <sip-address>. - - - callCliDescription - "call sip-address=<sip-address>" + Initie un appel vers la sip-address. initiateConferenceFunctionDescription - Initie une conférence d'id <id>. - - - initiateConferenceCliDescription - "initiate-conference sip-address=<ma sip-address> conference-id=<id>" + Initie une conférence. joinConferenceFunctionDescription - Rejoint la conférence n°<id> hébergée par la <sip-address de l'host> en tant que <nom>. Si vous êtes connecté à une proxy config, voir join-conference-as. - - - joinConferenceCliDescription - "join-conference sip-address=<sip-address de l'host> conference-id=<id> display-name=<nom>" + 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. joinConferenceAsFunctionDescription - Rejoint la conférence n°<id> hébergée par la <sip-address de l'host> en tant que <ma sip-address>. Si vous n'êtes pas connecté à une proxy-config, voir join-conference. - - - joinConferenceAsCliDescription - "join-conference-as sip-address=<sip-address de l'host> conference-id=<id> guest-sip-address=<ma sip-address>" + Rejoint la conférence hébergée par la sip-address avec la guest-sip-address. Si vous n'êtes pas connecté à une proxy-config, voir join-conference. diff --git a/src/app/cli/Cli.cpp b/src/app/cli/Cli.cpp index a18cee16e..d0f47d51a 100644 --- a/src/app/cli/Cli.cpp +++ b/src/app/cli/Cli.cpp @@ -219,13 +219,11 @@ static string multilineIndent (const QString &str, int indentationNumber = 0) { Cli::Command::Command ( const QString &functionName, const char *functionDescription, - const char *cliDescription, Cli::Function function, const QHash &argsScheme ) : mFunctionName(functionName), mFunctionDescription(functionDescription), - mCliDescription(cliDescription), mFunction(function), mArgsScheme(argsScheme) {} @@ -275,6 +273,30 @@ void Cli::Command::executeUri (const shared_ptr &address) con 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. @@ -283,17 +305,17 @@ QRegExp Cli::mRegExpArgs("(?:(?:([\\w-]+)\\s*)=\\s*(?:\"([^\"\\\\]*(?:\\\\.[^\"\ QRegExp Cli::mRegExpFunctionName("^\\s*([a-z-]+)\\s*"); QMap Cli::mCommands = { - createCommand("show", QT_TR_NOOP("showFunctionDescription"), QT_TR_NOOP("showCliDescription"), ::cliShow), - createCommand("call", QT_TR_NOOP("callFunctionDescription"), QT_TR_NOOP("callCliDescription"), ::cliCall, { + createCommand("show", QT_TR_NOOP("showFunctionDescription"), ::cliShow), + createCommand("call", QT_TR_NOOP("callFunctionDescription"), ::cliCall, { { "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", {} } }), - 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", {} } }), - 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", {} } }) }; @@ -354,7 +376,7 @@ void Cli::showHelp () { multilineIndent(tr("commandsName")) << endl; 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) << endl; } @@ -364,11 +386,10 @@ void Cli::showHelp () { pair Cli::createCommand ( const QString &functionName, const char *functionDescription, - const char *cliDescription, Function function, const QHash &argsScheme ) { - return { functionName, Cli::Command(functionName, functionDescription, cliDescription, function, argsScheme) }; + return { functionName, Cli::Command(functionName, functionDescription, function, argsScheme) }; } // ----------------------------------------------------------------------------- diff --git a/src/app/cli/Cli.hpp b/src/app/cli/Cli.hpp index 9c1a41b8d..b9beb99c0 100644 --- a/src/app/cli/Cli.hpp +++ b/src/app/cli/Cli.hpp @@ -60,7 +60,6 @@ class Cli : public QObject { Command ( const QString &functionName, const char *functionDescription, - const char *cliDescription, Function function, const QHash &argsScheme ); @@ -72,14 +71,11 @@ class Cli : public QObject { return mFunctionDescription; } - const char *getCliDescription () const { - return mCliDescription; - } + QString getFunctionSyntax () const ; private: QString mFunctionName; const char *mFunctionDescription; - const char *mCliDescription; Function mFunction = nullptr; QHash mArgsScheme; }; @@ -103,7 +99,6 @@ private: static std::pair createCommand ( const QString &functionName, const char *functionDescription, - const char *cliDescription, Function function, const QHash &argsScheme = QHash() );