Skip to content

Commit b301430

Browse files
committed
Use a proper command line parser
1 parent 5c42020 commit b301430

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "QObject"
22
#include "QPushButton"
3+
#include "QCommandLineParser"
34
#include "mainwindow.h"
45
#include <QApplication>
56

@@ -10,9 +11,18 @@ int main(int argc, char *argv[]) {
1011
a.setOrganizationDomain("carsonip.github.io");
1112
a.setApplicationName("Penguin Subtitle Player");
1213
a.setApplicationVersion(APP_VERSION);
14+
15+
QCommandLineParser parser;
16+
parser.setApplicationDescription("Penguin Subtitle Player");
17+
parser.addHelpOption();
18+
parser.addVersionOption();
19+
parser.addPositionalArgument("file", QCoreApplication::translate("main", "Subtitle file to play, optionally."), "[file]");
20+
parser.process(a);
21+
const QStringList args = parser.positionalArguments();
22+
1323
MainWindow w;
14-
if (argc > 1) {
15-
QString path = a.arguments().at(1);
24+
if (args.length() > 0) {
25+
QString path = args.at(0);
1626
w.load(path);
1727
}
1828
w.show();

0 commit comments

Comments
 (0)