Skip to content

Commit

Permalink
WIP7
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Jul 24, 2023
1 parent 3139ad1 commit 84be6be
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../gui/gui_application.h"
#include "app_module.h"
#include "cli_export.h"
#include "commands_help.h"
#include "console.h"
#include "document_tree_node_properties_providers.h"
#include "filepath_conv.h"
Expand Down Expand Up @@ -82,6 +83,7 @@ struct CommandLineArguments {
std::vector<FilePath> listFilepathToExport;
std::vector<FilePath> listFilepathToOpen;
bool cliProgressReport = true;
bool showSystemInformation = false;
};

// Provides customization of Qt message handler
Expand Down Expand Up @@ -228,6 +230,12 @@ static CommandLineArguments processCommandLine()
);
cmdParser.addOption(cmdCliNoProgress);

const QCommandLineOption cmdSysInfo(
QStringList{ "system-info" },
Main::tr("Show detailed system information and quit")
);
cmdParser.addOption(cmdSysInfo);

cmdParser.addPositionalArgument(
Main::tr("files"),
Main::tr("Files to open at startup, optionally"),
Expand Down Expand Up @@ -268,6 +276,7 @@ static CommandLineArguments processCommandLine()
args.includeDebugLogs = cmdParser.isSet(cmdDebugLogs);
#endif
args.cliProgressReport = !cmdParser.isSet(cmdCliNoProgress);
args.showSystemInformation = cmdParser.isSet(cmdSysInfo);

return args;
}
Expand Down Expand Up @@ -396,7 +405,6 @@ static void initGui(GuiApplication* guiApp)
if (!propForceOpenGlFallbackWidget && hasQGuiApplication) { // QOpenGL requires QGuiApplication
const std::string strGlVersion = queryGlVersionString();
const QVersionNumber glVersion = parseSemanticVersionString(strGlVersion);
qInfo() << fmt::format("OpenGL v{}.{}", glVersion.majorVersion(), glVersion.minorVersion()).c_str();
if (!glVersion.isNull() && glVersion.majorVersion() >= 2) { // Requires at least OpenGL version >= 2.0
setFunctionCreateGraphicsDriver(&QOpenGLWidgetOccView::createCompatibleGraphicsDriver);
IWidgetOccView::setCreator(&QOpenGLWidgetOccView::create);
Expand Down Expand Up @@ -490,6 +498,11 @@ static int runApp(QCoreApplication* qtApp)
appModule->properties()->retranslate();

// Process CLI
if (args.showSystemInformation) {
std::cout << Mayo::CommandSystemInformation::data().toStdString() << std::endl;
return 0;
}

if (!args.listFilepathToExport.empty()) {
if (args.listFilepathToOpen.empty())
fnCriticalExit(Main::tr("No input files -> nothing to export"));
Expand Down Expand Up @@ -581,7 +594,7 @@ int main(int argc, char* argv[])
QCoreApplication::setOrganizationDomain("www.fougue.pro");
QCoreApplication::setApplicationName("Mayo");
QCoreApplication::setApplicationVersion(QString::fromUtf8(Mayo::strVersion));
const bool isAppCliMode = fnArgsContainAnyOf({ "-e", "--export", "-h", "--help", "-v", "--version" });
const bool isAppCliMode = fnArgsContainAnyOf({ "-e", "--export", "-h", "--help", "-v", "--version", "--system-info" });
std::unique_ptr<QCoreApplication> ptrApp(
isAppCliMode ? new QCoreApplication(argc, argv) : new QApplication(argc, argv)
);
Expand All @@ -595,7 +608,7 @@ int main(int argc, char* argv[])
#endif

// Configure for CLI mode
if (isAppCliMode) {
if (isAppCliMode && fnArgsContainAnyOf({ "--system-info" })) {
#if defined(Q_OS_WIN) && defined(NDEBUG)
qAddPostRoutine(&Mayo::consoleSendEnterKey);
// https://devblogs.microsoft.com/oldnewthing/20090101-00/?p=19643
Expand Down

0 comments on commit 84be6be

Please sign in to comment.