#include "cli/CliRunner.h" #include #include #include #ifndef NO_GUI #include "gui/MainWindow.h" #include #endif /** * @brief Application entry point. * * Supports two operating modes: * * **GUI mode** (default when compiled with Qt): * Launches the Qt MainWindow. * * **CLI / batch mode** (activated by `--cli` or `--batch`): * Processes files from the command line or a config file without any GUI. * Progress is written to stderr; errors are logged but do not abort the batch. * * @note The `--batch` flag (or `--config `) implies CLI mode. */ int main(int argc, char* argv[]) { // Determine whether CLI/batch mode was requested. bool cli_mode = false; for (int i = 1; i < argc; ++i) { const std::string arg{argv[i]}; if (arg == "--cli" || arg == "--batch" || arg == "--config") { cli_mode = true; break; } } if (cli_mode) { // ── CLI / Batch mode (no Qt dependency) ───────────────────────────── auto config_result = photoconv::CliRunner::parse_args(argc, argv); if (!config_result.has_value()) { // "Help requested" is not an error – exit 0. const bool is_help = config_result.error().message == "Help requested"; if (!is_help) { std::cerr << config_result.error().format() << std::endl; } return is_help ? 0 : 1; } photoconv::CliRunner runner; auto result = runner.run(config_result.value()); if (!result.has_value()) { std::cerr << result.error().format() << std::endl; return 1; } // Exit code 0 if at least one file was converted, 1 otherwise. return result.value() > 0 ? 0 : 1; } #ifndef NO_GUI // ── GUI mode ───────────────────────────────────────────────────────────── QApplication app{argc, argv}; app.setApplicationName("Photo Converter"); app.setApplicationVersion("0.1.0"); app.setOrganizationName("photo-converter"); photoconv::MainWindow window; window.show(); return app.exec(); #else std::cerr << "This build was compiled without GUI support.\n" "Use --cli or --batch mode.\n"; return 1; #endif }