mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 14:44:01 +00:00
feat(Cli.cpp) : add the --cli-help option to display the help of the cli
This commit is contained in:
parent
d7baf78030
commit
e43fb27ac9
5 changed files with 246 additions and 45 deletions
|
|
@ -60,14 +60,6 @@
|
|||
<source>commandLineOptionConfigArg</source>
|
||||
<translation>file</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineOptionCmd</source>
|
||||
<translation>run a command line</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineOptionCmdArg</source>
|
||||
<translation>command line</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineOptionHelp</source>
|
||||
<translation>show this help</translation>
|
||||
|
|
@ -76,6 +68,14 @@
|
|||
<source>commandLineOptionVersion</source>
|
||||
<translation>show app version</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineCliHelp</source>
|
||||
<translation>displays the help menu to use Linphone with the CLI.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineDescription</source>
|
||||
<translation>send aan order to the application towards a command line.</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>AssistantAbstractView</name>
|
||||
|
|
@ -413,25 +413,61 @@ Server url not configured.</translation>
|
|||
</context>
|
||||
<context>
|
||||
<name>Cli</name>
|
||||
<message>
|
||||
<source>linphoneCliDescription</source>
|
||||
<translation>Way to control the Linphone application through command lines.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>uriCommandLineSyntax</source>
|
||||
<translation>linphone sip:<sip-address>?method=<method>([&<argument>=<base64-encoded-value>]*)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>cliCommandLineSyntax</source>
|
||||
<translation>linphone "<method> ([<argument>=<value>]*)"</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandsName</source>
|
||||
<translation>commands list :</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>showFunctionDescription</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Shows the main window of the application.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>showFunctionCall</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<source>showCliDescription</source>
|
||||
<translation>"show"</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joinConferenceFunctionDescription</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<source>callFunctionDescription</source>
|
||||
<translation>Initiates a call towards <sip-address>.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>callCliDescription</source>
|
||||
<translation>"call sip-address=<sip-address>"</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>initiateConferenceFunctionDescription</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<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>
|
||||
</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>
|
||||
</message>
|
||||
<message>
|
||||
<source>joinConferenceAsFunctionDescription</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<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>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
|
|
|
|||
|
|
@ -60,14 +60,6 @@
|
|||
<source>commandLineOptionConfigArg</source>
|
||||
<translation>file</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineOptionCmd</source>
|
||||
<translation>éxécuter une ligne de commande</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineOptionCmdArg</source>
|
||||
<translation>ligne de commande</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineOptionHelp</source>
|
||||
<translation>affiche cette aide</translation>
|
||||
|
|
@ -76,6 +68,14 @@
|
|||
<source>commandLineOptionVersion</source>
|
||||
<translation>affiche la version de l'application</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineCliHelp</source>
|
||||
<translation>affiche le menu d'aide pour l'utilisation de Linphone en CLI.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineDescription</source>
|
||||
<translation>envoie un ordre à l'application Linphone, voir --cli-help pour plus de détails.</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>AssistantAbstractView</name>
|
||||
|
|
@ -413,25 +413,61 @@ Url du serveur non configurée.</translation>
|
|||
</context>
|
||||
<context>
|
||||
<name>Cli</name>
|
||||
<message>
|
||||
<source>linphoneCliDescription</source>
|
||||
<translation>Moyen d'effectuer des actions sur l'application Linphone en ligne de commande.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>uriCommandLineSyntax</source>
|
||||
<translation>linphone sip:<sip-address>?method=<method>([&<argument>=<valeur-en-base64>]*)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>cliCommandLineSyntax</source>
|
||||
<translation>linphone "<method> ([<argument>=<valeur>]*)"</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandsName</source>
|
||||
<translation>liste des commandes :</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>showFunctionDescription</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Affiche la fenêtre principale de l'application.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>showFunctionCall</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<source>showCliDescription</source>
|
||||
<translation>"show"</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>joinConferenceFunctionDescription</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<source>callFunctionDescription</source>
|
||||
<translation>Initie un appel vers <sip-address>.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>callCliDescription</source>
|
||||
<translation>"call sip-address=<sip-address>"</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>initiateConferenceFunctionDescription</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<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>
|
||||
</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>
|
||||
</message>
|
||||
<message>
|
||||
<source>joinConferenceAsFunctionDescription</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<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>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
|
|
|
|||
|
|
@ -100,6 +100,12 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U
|
|||
mParser->showHelp();
|
||||
}
|
||||
|
||||
if(mParser->isSet("cli-help")){
|
||||
mCli = new Cli(this);
|
||||
mCli->showHelp();
|
||||
::exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (mParser->isSet("version"))
|
||||
mParser->showVersion();
|
||||
|
||||
|
|
@ -327,11 +333,12 @@ void App::createParser () {
|
|||
|
||||
mParser = new QCommandLineParser();
|
||||
mParser->setApplicationDescription(tr("applicationDescription"));
|
||||
mParser->addPositionalArgument("command",tr("commandLineDescription"),"[command]");
|
||||
mParser->addOptions({
|
||||
{ { "h", "help" }, tr("commandLineOptionHelp") },
|
||||
{ "cli-help", tr("commandLineCliHelp") },
|
||||
{ { "v", "version" }, tr("commandLineOptionVersion") },
|
||||
{ "config", tr("commandLineOptionConfig"), tr("commandLineOptionConfigArg") },
|
||||
{ { "c", "cmd" }, tr("commandLineOptionCmd"), tr("commandLineOptionCmdArg") },
|
||||
#ifndef Q_OS_MACOS
|
||||
{ "iconified", tr("commandLineOptionIconified") },
|
||||
#endif // ifndef Q_OS_MACOS
|
||||
|
|
|
|||
|
|
@ -137,12 +137,14 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
|
|||
|
||||
Cli::Command::Command (
|
||||
const QString &functionName,
|
||||
const QString &description,
|
||||
const QString &functionDescription,
|
||||
const QString &cliDescription,
|
||||
Cli::Function function,
|
||||
const QHash<QString, Cli::Argument> &argsScheme
|
||||
) :
|
||||
mFunctionName(functionName),
|
||||
mDescription(description),
|
||||
mFunctionDescription(functionDescription),
|
||||
mCliDescription(cliDescription),
|
||||
mFunction(function),
|
||||
mArgsScheme(argsScheme) {}
|
||||
|
||||
|
|
@ -200,17 +202,17 @@ QRegExp Cli::mRegExpArgs("(?:(?:([\\w-]+)\\s*)=\\s*(?:\"([^\"\\\\]*(?:\\\\.[^\"\
|
|||
QRegExp Cli::mRegExpFunctionName("^\\s*([a-z-]+)\\s*");
|
||||
|
||||
Cli::Cli (QObject *parent) : QObject(parent) {
|
||||
addCommand("show", tr("showFunctionDescription"), ::cliShow);
|
||||
addCommand("call", tr("showFunctionCall"), ::cliCall, {
|
||||
addCommand("show", tr("showFunctionDescription"), tr("showCliDescription"), ::cliShow);
|
||||
addCommand("call", tr("callFunctionDescription"), tr("callCliDescription"), ::cliCall, {
|
||||
{ "sip-address", {} }
|
||||
});
|
||||
addCommand("initiate-conference", tr("initiateConferenceFunctionDescription"), ::cliInitiateConference, {
|
||||
addCommand("initiate-conference", tr("initiateConferenceFunctionDescription"), tr("initiateConferenceCliDescription"), ::cliInitiateConference, {
|
||||
{ "sip-address", {} }, { "conference-id", {} }
|
||||
});
|
||||
addCommand("join-conference", tr("joinConferenceFunctionDescription"), ::cliJoinConference, {
|
||||
addCommand("join-conference", tr("joinConferenceFunctionDescription"), tr("joinConferenceCliDescription"), ::cliJoinConference, {
|
||||
{ "sip-address", {} }, { "conference-id", {} }, { "display-name", {} }
|
||||
});
|
||||
addCommand("join-conference-as", tr("joinConferenceAsFunctionDescription"), ::cliJoinConferenceAs, {
|
||||
addCommand("join-conference-as", tr("joinConferenceAsFunctionDescription"), tr("joinConferenceAsCliDescription"), ::cliJoinConferenceAs, {
|
||||
{ "sip-address", {} }, { "conference-id", {} }, { "guest-sip-address", {} }
|
||||
});
|
||||
}
|
||||
|
|
@ -219,14 +221,22 @@ Cli::Cli (QObject *parent) : QObject(parent) {
|
|||
|
||||
void Cli::addCommand (
|
||||
const QString &functionName,
|
||||
const QString &description,
|
||||
const QString &functionDescription,
|
||||
const QString &cliDescription,
|
||||
Function function,
|
||||
const QHash<QString, Argument> &argsScheme
|
||||
) {
|
||||
if (mCommands.contains(functionName))
|
||||
if (mCommands.contains(functionName)) {
|
||||
qWarning() << QStringLiteral("Command already exists: `%1`.").arg(functionName);
|
||||
else
|
||||
mCommands[functionName] = Cli::Command(functionName, description, function, argsScheme);
|
||||
return;
|
||||
}
|
||||
mCommands[functionName] = Cli::Command(
|
||||
functionName,
|
||||
functionDescription,
|
||||
cliDescription,
|
||||
function,
|
||||
argsScheme
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -274,6 +284,104 @@ void Cli::executeCommand (const QString &command, CommandFormat *format) const {
|
|||
mCommands[functionName].executeUri(address);
|
||||
}
|
||||
|
||||
QString splitWord(QString word, int &curPos, const int lineLength, const QString &padding) {
|
||||
QString out;
|
||||
out += word.mid(0,lineLength - curPos) + "\n" + padding;
|
||||
curPos = padding.length();
|
||||
word = word.mid(lineLength - curPos);
|
||||
while(word.length() > lineLength - curPos) {
|
||||
out += word.mid(0,lineLength - curPos);
|
||||
word = word.mid(lineLength - curPos);
|
||||
out += "\n" + padding;
|
||||
}
|
||||
out += word;
|
||||
curPos = word.length() + padding.length();
|
||||
return out;
|
||||
}
|
||||
|
||||
QString indentedWord(QString word, int &curPos, const int lineLength, const QString &padding){
|
||||
QString out;
|
||||
if (curPos + word.length() > lineLength ) {
|
||||
if (padding.length() + word.length() > lineLength) {
|
||||
out += splitWord(word, curPos, lineLength, padding);
|
||||
} else {
|
||||
out += QStringLiteral("\n");
|
||||
out += padding + word;
|
||||
curPos = padding.length();
|
||||
}
|
||||
} else {
|
||||
out += word;
|
||||
curPos += word.length();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static string multilineIndent (const QString &str, int indentationNumber = 0) {
|
||||
|
||||
static const int lineLength(80);
|
||||
static const QRegExp spaceRegexp("(\\s)");
|
||||
const QString padding(indentationNumber * 2, ' ');
|
||||
|
||||
QString out = padding;
|
||||
|
||||
int indentedTextCurPos = padding.length();
|
||||
|
||||
int spacePos = 0;
|
||||
int wordPos = spacePos;
|
||||
QString word;
|
||||
|
||||
while ((spacePos = spaceRegexp.indexIn(str, spacePos)) != -1) {
|
||||
word = str.mid(wordPos,spacePos-wordPos);
|
||||
out += indentedWord(word, indentedTextCurPos, lineLength, padding);
|
||||
switch (str[spacePos].unicode()) {
|
||||
case '\n':
|
||||
out += "\n" + padding;
|
||||
indentedTextCurPos = padding.length();
|
||||
break;
|
||||
case '\t': //tabulated as a space
|
||||
case ' ':
|
||||
if (indentedTextCurPos == lineLength) {
|
||||
out += "\n" + padding;
|
||||
indentedTextCurPos = padding.length();
|
||||
} else {
|
||||
out += " ";
|
||||
indentedTextCurPos += 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case '\r':
|
||||
case '\f':
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
spacePos += 1;
|
||||
wordPos = spacePos;
|
||||
}
|
||||
word = str.mid(wordPos);
|
||||
out += indentedWord(word, indentedTextCurPos,lineLength, padding);
|
||||
out += "\n";
|
||||
|
||||
return ::Utils::appStringToCoreString(out);
|
||||
}
|
||||
|
||||
void Cli::showHelp() {
|
||||
cout << multilineIndent(tr("linphoneCliDescription"),0);
|
||||
cout << "\n" << "Usage : " << "\n";
|
||||
cout << multilineIndent(tr("uriCommandLineSyntax"),0);
|
||||
cout <<multilineIndent(tr("cliCommandLineSyntax"),0);
|
||||
cout << "\n";
|
||||
cout << multilineIndent(tr("commandsName"));
|
||||
|
||||
cout << "\n";
|
||||
for (const auto &method : mCommands.keys()) {
|
||||
cout << multilineIndent(mCommands[method].getCliDescription(),1);
|
||||
cout << multilineIndent(mCommands[method].getFunctionDescription(),2);
|
||||
cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
QString Cli::parseFunctionName (const QString &command) const {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ class Cli : public QObject {
|
|||
Command () = default;
|
||||
Command (
|
||||
const QString &functionName,
|
||||
const QString &description,
|
||||
const QString &functionDescription,
|
||||
const QString &cliDescription,
|
||||
Function function,
|
||||
const QHash<QString, Argument> &argsScheme
|
||||
);
|
||||
|
|
@ -66,9 +67,19 @@ class Cli : public QObject {
|
|||
void execute (QHash<QString, QString> &args) const;
|
||||
void executeUri (const std::shared_ptr<linphone::Address> &address) const;
|
||||
|
||||
QString getFunctionDescription() {
|
||||
return mFunctionDescription;
|
||||
}
|
||||
|
||||
QString getCliDescription() {
|
||||
return mCliDescription;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
QString mFunctionDescription;
|
||||
QString mCliDescription;
|
||||
QString mFunctionName;
|
||||
QString mDescription;
|
||||
Function mFunction = nullptr;
|
||||
QHash<QString, Argument> mArgsScheme;
|
||||
};
|
||||
|
|
@ -85,10 +96,13 @@ public:
|
|||
|
||||
void executeCommand (const QString &command, CommandFormat *format = nullptr) const;
|
||||
|
||||
void showHelp();
|
||||
|
||||
private:
|
||||
void addCommand (
|
||||
const QString &functionName,
|
||||
const QString &description,
|
||||
const QString &functionDescription,
|
||||
const QString &cliDescription,
|
||||
Function function,
|
||||
const QHash<QString, Argument> &argsScheme = QHash<QString, Argument>()
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue