dragger: use actual argument parsing

This commit is contained in:
Bruno BELANYI 2021-10-08 15:27:36 +02:00
parent 66747de1bb
commit 5002193c63

View file

@ -1,4 +1,5 @@
#include <QApplication>
#include <QCommandLineParser>
#include <QDebug>
#include <QDrag>
#include <QFile>
@ -9,10 +10,23 @@
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
QApplication::setApplicationName("dragger");
QApplication::setApplicationVersion("0.1.0");
QCommandLineParser parser;
parser.setApplicationDescription("A CLI drag-and-drop tool");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument(
"files",
QCoreApplication::translate("files", "files to drag-and-drop"),
"[FILES...]");
parser.process(app);
QList<QUrl> urls;
for (int i = 1; i < argc; ++i) {
QFileInfo file(QFile(argv[i]));
for (auto const& path : parser.positionalArguments()) {
QFileInfo file{QFile{path}};
if (file.exists()) {
urls << QUrl("file:" + file.absoluteFilePath());
} else {