Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ target_link_libraries(fstl Qt5::Widgets Qt5::Core Qt5::Gui Qt5::OpenGL ${OPENGL_
# Add version definitions to use within the code.
target_compile_definitions(fstl PRIVATE -DFSTL_VERSION="${PROJECT_VERSION}")

# Enable a simple test that validates the CLI `--version` output is exact.
# Escape dots in PROJECT_VERSION so version is matched literally in the regex. Use character class to avoid backslash escaping issues.
string(REPLACE "." "[.]" PROJECT_VERSION_ESCAPED "${PROJECT_VERSION}")

enable_testing()
add_test(NAME version_check COMMAND $<TARGET_FILE:fstl> --version)
set_tests_properties(version_check PROPERTIES PASS_REGULAR_EXPRESSION "fstl ${PROJECT_VERSION_ESCAPED}")

# Also validate the POSIX-compliant short alias `-V` produces the same output.
add_test(NAME version_check_V COMMAND $<TARGET_FILE:fstl> -V)
set_tests_properties(version_check_V PROPERTIES PASS_REGULAR_EXPRESSION "fstl ${PROJECT_VERSION_ESCAPED}")

#installer information that is platform independent
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Fast .stl file viewer.")
set(CPACK_PACKAGE_VERSION_MAJOR ${FSTL_VERSION_MAJOR})
Expand Down
22 changes: 22 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <iostream>
#include <QApplication>
#include <QCommandLineParser>

#include "app.h"

Expand All @@ -11,7 +13,27 @@ int main(int argc, char* argv[])
QCoreApplication::setOrganizationDomain("https://github.com/fstl-app/fstl");
QCoreApplication::setApplicationName("fstl");
QCoreApplication::setApplicationVersion(FSTL_VERSION);

App a(argc, argv);

// Set up QCommandLineParser to handle --help, --version, and file argument
QCommandLineParser parser;
parser.setApplicationDescription("Fast .stl file viewer");
parser.addHelpOption();

// Add custom version option with both -V (uppercase, POSIX) and --version
QCommandLineOption versionOption(QStringList{"V", "version"}, "Displays version information.");
parser.addOption(versionOption);

parser.addPositionalArgument("file", "STL file to open (optional)", "[file]");
parser.process(a);

// Handle version option manually since we use custom -V
if (parser.isSet(versionOption)) {
std::cout << QCoreApplication::applicationName().toStdString() << " "
<< QCoreApplication::applicationVersion().toStdString() << "\n";
return 0;
}

return a.exec();
}
Loading