mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-02-07 15:08:24 +00:00
feat(Cli): method syntax auto generated when --cli-help
This commit is contained in:
parent
0721a22be8
commit
86cfc1c816
4 changed files with 41 additions and 65 deletions
|
|
@ -431,43 +431,23 @@ Server url not configured.</translation>
|
|||
</message>
|
||||
<message>
|
||||
<source>showFunctionDescription</source>
|
||||
<translation>Shows the main window of the application.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>showCliDescription</source>
|
||||
<translation>"show"</translation>
|
||||
<translation>Show the main window of the application.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>callFunctionDescription</source>
|
||||
<translation>Initiates a call towards <sip-address>.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>callCliDescription</source>
|
||||
<translation>"call sip-address=<sip-address>"</translation>
|
||||
<translation>Initiate a call to the sip-address.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>initiateConferenceFunctionDescription</source>
|
||||
<translation>Initiates a conference of id <id>.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>initiateConferenceCliDescription</source>
|
||||
<translation>"initiate-conference sip-address=<my sip-address> conference-id=<id>"</translation>
|
||||
<translation>Initiate a conference.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joinConferenceFunctionDescription</source>
|
||||
<translation>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.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joinConferenceCliDescription</source>
|
||||
<translation>"join-conference sip-address=<host sip-address> conference-id=<id> display-name=<name>"</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>joinConferenceAsFunctionDescription</source>
|
||||
<translation>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.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joinConferenceAsCliDescription</source>
|
||||
<translation>"join-conference-as sip-address=<host sip-address> conference-id=<id> guest-sip-address=<my sip-address>"</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>
|
||||
</context>
|
||||
<context>
|
||||
|
|
|
|||
|
|
@ -433,41 +433,21 @@ Url du serveur non configurée.</translation>
|
|||
<source>showFunctionDescription</source>
|
||||
<translation>Affiche la fenêtre principale de l'application.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>showCliDescription</source>
|
||||
<translation>"show"</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>callFunctionDescription</source>
|
||||
<translation>Initie un appel vers <sip-address>.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>callCliDescription</source>
|
||||
<translation>"call sip-address=<sip-address>"</translation>
|
||||
<translation>Initie un appel vers la sip-address.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>initiateConferenceFunctionDescription</source>
|
||||
<translation>Initie une conférence d'id <id>.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>initiateConferenceCliDescription</source>
|
||||
<translation>"initiate-conference sip-address=<ma sip-address> conference-id=<id>"</translation>
|
||||
<translation>Initie une conférence.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joinConferenceFunctionDescription</source>
|
||||
<translation>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.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joinConferenceCliDescription</source>
|
||||
<translation>"join-conference sip-address=<sip-address de l'host> conference-id=<id> display-name=<nom>"</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>joinConferenceAsFunctionDescription</source>
|
||||
<translation>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.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joinConferenceAsCliDescription</source>
|
||||
<translation>"join-conference-as sip-address=<sip-address de l'host> conference-id=<id> guest-sip-address=<ma sip-address>"</translation>
|
||||
<translation>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.</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
|
|
|
|||
|
|
@ -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<QString, Cli::Argument> &argsScheme
|
||||
) :
|
||||
mFunctionName(functionName),
|
||||
mFunctionDescription(functionDescription),
|
||||
mCliDescription(cliDescription),
|
||||
mFunction(function),
|
||||
mArgsScheme(argsScheme) {}
|
||||
|
||||
|
|
@ -275,6 +273,30 @@ void Cli::Command::executeUri (const shared_ptr<linphone::Address> &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<QString, Cli::Command> 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<QString, Cli::Command> Cli::createCommand (
|
||||
const QString &functionName,
|
||||
const char *functionDescription,
|
||||
const char *cliDescription,
|
||||
Function function,
|
||||
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 {
|
|||
Command (
|
||||
const QString &functionName,
|
||||
const char *functionDescription,
|
||||
const char *cliDescription,
|
||||
Function function,
|
||||
const QHash<QString, Argument> &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<QString, Argument> mArgsScheme;
|
||||
};
|
||||
|
|
@ -103,7 +99,6 @@ private:
|
|||
static std::pair<QString, Command> createCommand (
|
||||
const QString &functionName,
|
||||
const char *functionDescription,
|
||||
const char *cliDescription,
|
||||
Function function,
|
||||
const QHash<QString, Argument> &argsScheme = QHash<QString, Argument>()
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue