dragger: use actual argument parsing
This commit is contained in:
parent
66747de1bb
commit
5002193c63
|
@ -1,4 +1,5 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QCommandLineParser>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@ -9,10 +10,23 @@
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
QApplication app(argc, 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;
|
QList<QUrl> urls;
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (auto const& path : parser.positionalArguments()) {
|
||||||
QFileInfo file(QFile(argv[i]));
|
QFileInfo file{QFile{path}};
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
urls << QUrl("file:" + file.absoluteFilePath());
|
urls << QUrl("file:" + file.absoluteFilePath());
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue