Skip to content

Commit 1c8bf61

Browse files
committed
Commandline parsing to get basic information about the app
1 parent 57542f6 commit 1c8bf61

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

src/main.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,46 @@
99
#include <QApplication>
1010
#include <QFontDatabase>
1111

12+
void parseCommands(QApplication &app, QCommandLineParser &parser)
13+
{
14+
parser.setApplicationDescription("Notes is a simple note-taking application.");
15+
parser.addHelpOption();
16+
parser.addVersionOption();
17+
parser.addOption(QCommandLineOption("count", "Count the number of notes"));
18+
parser.addOption(QCommandLineOption("trash-count", "Count the number of notes in the trash"));
19+
parser.addOption(QCommandLineOption("list-notes", "List all notes"));
20+
parser.process(app);
21+
22+
if (parser.isSet("version")) {
23+
qDebug() << "Notes version: " << APP_VERSION;
24+
exit(EXIT_SUCCESS);
25+
}
26+
if (parser.isSet("count")) {
27+
throw std::runtime_error("Not implemented yet");
28+
}
29+
if (parser.isSet("trash-count")) {
30+
throw std::runtime_error("Not implemented yet");
31+
}
32+
if (parser.isSet("list-notes")) {
33+
throw std::runtime_error("Not implemented yet");
34+
}
35+
}
36+
1237
int main(int argc, char *argv[])
1338
{
1439
QApplication app(argc, argv);
1540
// Set application information
16-
app.setApplicationName("Notes");
17-
app.setApplicationVersion(APP_VERSION);
41+
QApplication::setApplicationName("Notes");
42+
QApplication::setApplicationVersion(APP_VERSION);
1843

1944
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
20-
app.setDesktopFileName(APP_ID);
45+
QApplication::setDesktopFileName(APP_ID);
2146
#endif
2247

48+
// Parse command line arguments
49+
QCommandLineParser parser;
50+
parseCommands(app, parser);
51+
2352
if (QFontDatabase::addApplicationFont(":/fonts/fontawesome/fa-solid-900.ttf") < 0)
2453
qWarning() << "FontAwesome Solid cannot be loaded !";
2554

@@ -100,5 +129,5 @@ int main(int argc, char *argv[])
100129
QObject::connect(&instance, &SingleInstance::newInstance, &w,
101130
[&]() { (&w)->setMainWindowVisibility(true); });
102131

103-
return app.exec();
132+
return QApplication::exec();
104133
}

0 commit comments

Comments
 (0)