| 27 | }; |
| 28 | |
| 29 | CommandLineParseResult parseCommandLine(QCommandLineParser &parser, ParsedOptions *query) { |
| 30 | using Status = CommandLineParseResult::Status; |
| 31 | |
| 32 | const QCommandLineOption helpOption = parser.addHelpOption(); |
| 33 | const QCommandLineOption versionOption = parser.addVersionOption(); |
| 34 | parser.addPositionalArgument("file", "File to open"); |
| 35 | |
| 36 | if (!parser.parse(QCoreApplication::arguments())) |
| 37 | return { Status::Error, parser.errorText() }; |
| 38 | |
| 39 | if (parser.isSet(versionOption)) |
| 40 | return { Status::VersionRequested }; |
| 41 | |
| 42 | if (parser.isSet(helpOption)) |
| 43 | return { Status::HelpRequested }; |
| 44 | |
| 45 | const QStringList positionalArguments = parser.positionalArguments(); |
| 46 | if (!positionalArguments.isEmpty()) { |
| 47 | if (positionalArguments.size() > 1) |
| 48 | return { Status::Error, "Several 'name' arguments specified." }; |
| 49 | query->hasFile = true; |
| 50 | query->file = positionalArguments.first(); |
| 51 | } |
| 52 | |
| 53 | return { Status::Ok }; |
| 54 | } |
| 55 | |
| 56 | int main(int argc, char *argv[]) |
| 57 | { |