aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2021-02-05 03:18:26 +0100
committerRenaud G <renaud@rolisteam.org>2021-02-05 03:18:26 +0100
commit6753fff63d4bc3916388b1bfbc668980330887d8 (patch)
treee6e7bd9d56a2a63aeb3c80cc7f9ab3a76ef5de26
parentac9b0862524c574e2e6d4e4c93af0beb7eeaa549 (diff)
downloadOneRoll-6753fff63d4bc3916388b1bfbc668980330887d8.tar.gz
OneRoll-6753fff63d4bc3916388b1bfbc668980330887d8.zip
Add new output format
-rw-r--r--cli/main.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/cli/main.cpp b/cli/main.cpp
index 981c1a0..db265f7 100644
--- a/cli/main.cpp
+++ b/cli/main.cpp
@@ -245,11 +245,11 @@ void displayCommandResult(QString json, bool withColor)
auto comment= obj["comment"].toString();
auto arrayInst= obj["instructions"].toArray();
QStringList diceResults;
- for(auto inst : arrayInst)
+ for(const auto &inst : qAsConst(arrayInst))
{
auto obj= inst.toObject();
auto diceVals= obj["diceval"].toArray();
- for(auto diceval : diceVals)
+ for(const auto & diceval : qAsConst(diceVals))
{
auto objval= diceval.toObject();
auto resultStr= objval["string"].toString();
@@ -273,9 +273,9 @@ void displayCommandResult(QString json, bool withColor)
QString str;
if(withColor)
- str= QString("Result: \e[0;31m%1\e[0m - details:[%3 (%2)]").arg(scalarText).arg(diceList).arg(cmd);
+ str= QString("Result: \e[0;31m%1\e[0m - details:[%3 (%2)]").arg(scalarText, diceList, cmd);
else
- str= QString("Result: %1 - details:[%3 (%2)]").arg(scalarText).arg(diceList).arg(cmd);
+ str= QString("Result: %1 - details:[%3 (%2)]").arg(scalarText, diceList, cmd);
if(!resultStr.isEmpty() && resultStr != scalarText)
{
@@ -414,7 +414,7 @@ int startDiceParsing(QStringList& cmds, bool withColor, EXPORTFORMAT format, QJs
switch(format)
{
case TERMINAL:
- displayCommandResult(json, true);
+ displayCommandResult(json, withColor);
break;
case SVG:
out << displaySVG(json, withColor) << "\n";
@@ -487,6 +487,9 @@ int main(int argc, char* argv[])
QCommandLineOption json(QStringList() << "j"
<< "json",
"The output is formatted in json.");
+ QCommandLineOption line(QStringList() << "l"
+ << "line",
+ "The output is in one line [default].");
QCommandLineOption dotFile(QStringList() << "d"
<< "dot-file",
"Instead of rolling dice, generate the execution tree and write it in "
@@ -506,6 +509,7 @@ int main(int argc, char* argv[])
optionParser.addOption(alias);
optionParser.addOption(aliasData);
optionParser.addOption(character);
+ optionParser.addOption(line);
optionParser.addOption(markdown);
optionParser.addOption(bot);
optionParser.addOption(svg);
@@ -556,19 +560,16 @@ int main(int argc, char* argv[])
{
format= JSON;
}
- if(optionParser.isSet(help))
+ else if(optionParser.isSet(line))
{
- cmd= "help";
+ format = TEXT;
}
- QStringList cmdList= optionParser.positionalArguments();
- if(!cmdList.isEmpty())
+ if(optionParser.isSet(help))
{
- if(cmdList[0].startsWith('&'))
- {
- colorb= false;
- }
+ cmd= "help";
}
+ QStringList cmdList= optionParser.positionalArguments();
QJsonArray aliases;
if(optionParser.isSet(alias))