mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 19:13:52 +00:00
refactor(editor): hoist consumeJsonFlag into cli_arg_parse.hpp
The pattern
bool jsonOut = (i + 1 < argc &&
std::strcmp(argv[i + 1], "--json") == 0);
if (jsonOut) i++;
is repeated ~50 times across the editor — every --info-*
and --validate-* handler writes the same three lines to
detect and consume an optional --json follower. Extract
to consumeJsonFlag(int& i, int argc, char** argv) in
cli_arg_parse.hpp (the same header that already hosts
parseOptInt / parseOptFloat / parseOptUint / parseOptArg
for similar repeated patterns).
Adopted in the recently-added files:
• cli_world_map.cpp — both --info-womx and --validate-womx
• cli_sound_catalog.cpp — both --info-wsnd and --validate-wsnd
• cli_wom_info.cpp — all 7 --info-* / --validate-wom
handlers (replace_all)
Also adopted the shared stripExt() helper from
cli_box_emitter.hpp instead of the new files' rolled-
own stripWomxExt / stripWsndExt — same observable behavior,
no more local copies of the extension-strip logic.
Future --info-/-validate handlers added to other formats
(WSP, WTC, etc.) get the same one-line jsonOut detection
without reinventing the peek-and-advance dance. Any later
adoption of consumeJsonFlag in the older 50+ sites is now
a mechanical replace_all edit per file.
Behavior preserved: --validate-wom and --info-womx and
--info-wsnd round-trip exactly as before, both text and
--json output unchanged.
This commit is contained in:
parent
36d63d8dd0
commit
ec569768fe
4 changed files with 31 additions and 37 deletions
|
|
@ -1,4 +1,6 @@
|
|||
#include "cli_sound_catalog.hpp"
|
||||
#include "cli_arg_parse.hpp"
|
||||
#include "cli_box_emitter.hpp"
|
||||
|
||||
#include "pipeline/wowee_sound.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
|
@ -17,8 +19,7 @@ namespace cli {
|
|||
namespace {
|
||||
|
||||
std::string stripWsndExt(std::string base) {
|
||||
if (base.size() >= 5 && base.substr(base.size() - 5) == ".wsnd")
|
||||
base = base.substr(0, base.size() - 5);
|
||||
stripExt(base, ".wsnd");
|
||||
return base;
|
||||
}
|
||||
|
||||
|
|
@ -82,9 +83,7 @@ int handleGenTavern(int& i, int argc, char** argv) {
|
|||
|
||||
int handleInfo(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
bool jsonOut = (i + 1 < argc &&
|
||||
std::strcmp(argv[i + 1], "--json") == 0);
|
||||
if (jsonOut) i++;
|
||||
bool jsonOut = consumeJsonFlag(i, argc, argv);
|
||||
base = stripWsndExt(base);
|
||||
if (!wowee::pipeline::WoweeSoundLoader::exists(base)) {
|
||||
std::fprintf(stderr, "WSND not found: %s.wsnd\n", base.c_str());
|
||||
|
|
@ -138,9 +137,7 @@ int handleInfo(int& i, int argc, char** argv) {
|
|||
|
||||
int handleValidate(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
bool jsonOut = (i + 1 < argc &&
|
||||
std::strcmp(argv[i + 1], "--json") == 0);
|
||||
if (jsonOut) i++;
|
||||
bool jsonOut = consumeJsonFlag(i, argc, argv);
|
||||
base = stripWsndExt(base);
|
||||
if (!wowee::pipeline::WoweeSoundLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue