From eb95a296ecbbbf78721fca40fe40765155beb87c Mon Sep 17 00:00:00 2001 From: Richard Ward Date: Fri, 19 Dec 2025 02:21:04 +0000 Subject: [PATCH] mod cli --- README.md | 2 +- src/main.cpp | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ab10634..2bf139e 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ If you need the Conan runtime environment (e.g., because dependencies set env va ## Runtime configuration -`main.cpp` now uses a JSON-driven entrypoint. Use `sdl3_app --json-file-in ` to load a configuration that points at the Lua script and captures window dimensions, or run `sdl3_app --create-seed-json config/seed_runtime.json` to write a starter JSON file (based on the executable’s `scripts/cube_logic.lua` location). You can also use `sdl3_app --set-default-json` to store the current runtime JSON in the platform default directory (APPDATA on Windows, `XDG_CONFIG_HOME`/`$HOME/.config` elsewhere); when that default file exists, the app will pick it up automatically when launched without extra CLI options. If no JSON input is provided and no default exists, the app falls back to discovering `scripts/cube_logic.lua` next to the binary. +`main.cpp` now uses a JSON-driven entrypoint. Use `sdl3_app --json-file-in ` to load a configuration that points at the Lua script and captures window dimensions, or run `sdl3_app --create-seed-json config/seed_runtime.json` to write a starter JSON file (based on the executable’s `scripts/cube_logic.lua` location). You can also use `sdl3_app --set-default-json` (optionally followed by an existing JSON path) to copy the runtime JSON to the platform default directory (APPDATA on Windows, `XDG_CONFIG_HOME`/`$HOME/.config` elsewhere); when that default file exists, the app picks it up automatically when launched without extra CLI options. If no JSON input is provided and no default exists, the app falls back to discovering `scripts/cube_logic.lua` next to the binary. ## Dependency automation diff --git a/src/main.cpp b/src/main.cpp index 840b44a..47fd503 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -136,15 +136,19 @@ struct AppOptions { AppOptions ParseCommandLine(int argc, char** argv) { std::string jsonInputText; std::string seedOutputText; - bool setDefaultJson = false; + std::string setDefaultJsonPath; CLI::App app("SDL3 + Vulkan runtime helper"); app.add_option("-j,--json-file-in", jsonInputText, "Path to a runtime JSON config") ->check(CLI::ExistingFile); app.add_option("-s,--create-seed-json", seedOutputText, "Write a template runtime JSON file"); - app.add_flag("--set-default-json", setDefaultJson, - "Persist the runtime JSON to the platform default location (XDG/APPDATA)"); + auto* setDefaultJsonOption = app.add_option( + "--set-default-json", setDefaultJsonPath, + "Persist the runtime JSON to the platform default location (XDG/APPDATA); " + "pass a path to copy that JSON"); + setDefaultJsonOption->type_name("PATH"); + setDefaultJsonOption->type_size(0, 1); try { app.parse(argc, argv); @@ -153,9 +157,17 @@ AppOptions ParseCommandLine(int argc, char** argv) { throw; } + bool shouldSaveDefault = setDefaultJsonOption->count() > 0; + std::optional providedDefaultPath; + if (shouldSaveDefault && !setDefaultJsonPath.empty()) { + providedDefaultPath = std::filesystem::absolute(setDefaultJsonPath); + } + RuntimeConfig runtimeConfig; if (!jsonInputText.empty()) { runtimeConfig = LoadRuntimeConfigFromJson(std::filesystem::absolute(jsonInputText)); + } else if (providedDefaultPath) { + runtimeConfig = LoadRuntimeConfigFromJson(*providedDefaultPath); } else if (auto defaultPath = GetDefaultConfigPath(); defaultPath && std::filesystem::exists(*defaultPath)) { runtimeConfig = LoadRuntimeConfigFromJson(*defaultPath); @@ -168,7 +180,7 @@ AppOptions ParseCommandLine(int argc, char** argv) { if (!seedOutputText.empty()) { options.seedOutput = std::filesystem::absolute(seedOutputText); } - options.saveDefaultJson = setDefaultJson; + options.saveDefaultJson = shouldSaveDefault; return options; }