From 6301ec587d747d20518e2fee81eb551b44bc89ac Mon Sep 17 00:00:00 2001 From: Mark Long Date: Sat, 4 Oct 2025 13:02:15 -0500 Subject: [PATCH] Updated main() to allow --version and --help options. Added cmdline processing function. --- AI_PROJECT_HINTS.md | 11 ++++--- src/main.cxx | 71 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/AI_PROJECT_HINTS.md b/AI_PROJECT_HINTS.md index 936aab6..ac44ca5 100644 --- a/AI_PROJECT_HINTS.md +++ b/AI_PROJECT_HINTS.md @@ -19,11 +19,11 @@ This file contains project-specific information to help AI assistants work effec ## Application Type & Testing -### GUI Application - NO Command Line Interface +### GUI Application - Few Command Line Interface Arguments - **Application type**: Qt6 GUI application -- **Cannot test with**: `--help`, `--version`, or any CLI flags +- **It can be tested with**: `--help` or `--version`, both of which should exit - **Test method**: Launch GUI (`build/AppleSAWS`) or run specific tests -- **Entry point**: `main.cpp` launches Qt GUI +- **Entry point**: `main.cxx` launches Qt GUI ## Development Standards & Preferences @@ -94,10 +94,9 @@ This file contains project-specific information to help AI assistants work effec - ✅ Always use `./build.sh` or CMake commands ### Application Testing -- ❌ Don't try `build/AppleSAWS --help` (GUI app, no CLI) -- ❌ Don't expect command-line output for testing +- ✅ Use `--help` or `--version` for quick smoke tests (both exit without launching the GUI) - ✅ Build success indicates code correctness -- ✅ Can launch GUI for functional testing (`build/AppleSAWS`) +- ✅ Launch the GUI for functional testing (`build/AppleSAWS`) ### Code Style - ❌ Don't use old-style Qt SIGNAL/SLOT macros diff --git a/src/main.cxx b/src/main.cxx index 5e3713f..8b6f878 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -1,28 +1,65 @@ -#include -#include -#include -#include -#include - #include "StartupDialog.h" +#include +#include +#include +#include +#include +#include + +namespace +{ + constexpr auto OrganizationName = QStringView{u"LydianScaleSoftware"}; + constexpr auto OrganizationDomain = QStringView{u"lydianscale.com"}; + constexpr auto ApplicationName = QStringView{u"AppleSAWS"}; + constexpr auto ApplicationVersion = QStringView{u"development"}; + constexpr auto ApplicationDescription = QStringView{u"Apple II disk image and file exploration toolkit."}; + + void processArguments(QCoreApplication& app) + { + QCommandLineParser parser; + parser.setApplicationDescription(QString{ApplicationDescription}); + const QCommandLineOption helpOption = parser.addHelpOption(); + const QCommandLineOption versionOption = parser.addVersionOption(); + + parser.process(app); + + if (parser.isSet(helpOption)) + { + parser.showHelp(); + } + + if (parser.isSet(versionOption)) + { + parser.showVersion(); + } + } +} + int main(int argc, char** argv) { - QApplication a(argc, argv); - QCoreApplication::setOrganizationName("LydianScaleSoftware"); - QCoreApplication::setOrganizationDomain("lydianscale.com"); - QCoreApplication::setApplicationName("AppleSAWS"); + QApplication app(argc, argv); + QCoreApplication::setOrganizationName(QString{OrganizationName}); + QCoreApplication::setOrganizationDomain(QString{OrganizationDomain}); + QCoreApplication::setApplicationName(QString{ApplicationName}); + QCoreApplication::setApplicationVersion(QString{ApplicationVersion}); - auto x = QFontDatabase::addApplicationFont(":/fonts/Print_Char_21.ttf"); - auto y = QFontDatabase::addApplicationFont(":/fonts/PR_Number_3.ttf"); + processArguments(app); - if (x < 0) { qWarning("Could not load Print_Char_21.ttf font."); } - if (y < 0) { qWarning("Could not load PR_Number_3.ttf font."); } + const auto loadFont = [](const QString& resourcePath, QStringView friendlyName) { + if (QFontDatabase::addApplicationFont(resourcePath) < 0) + { + qWarning().noquote() << QStringLiteral("Could not load %1 font.").arg(friendlyName); + } + }; - StartupDialog w; - w.show(); + loadFont(QStringLiteral(":/fonts/Print_Char_21.ttf"), QStringLiteral("Print_Char_21.ttf")); + loadFont(QStringLiteral(":/fonts/PR_Number_3.ttf"), QStringLiteral("PR_Number_3.ttf")); - return a.exec(); + StartupDialog startupDialog; + startupDialog.show(); + + return app.exec(); }