From 39adf93e4628834ca9e537bee321a27fef496267 Mon Sep 17 00:00:00 2001 From: TaurusXin Date: Wed, 25 Sep 2024 23:08:14 +0800 Subject: [PATCH] feat: handle exception --- src/main.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1777176..f7f1658 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,7 +24,7 @@ void processFile(const fs::path &filePath, const fs::path &outputFolder) } // skip if not ending with ".ncm" - if (!filePath.has_extension() || filePath.extension().u8string()!= ".ncm") + if (!filePath.has_extension() || filePath.extension().u8string() != ".ncm") { return; } @@ -65,8 +65,23 @@ int main(int argc, char **argv) options.parse_positional({"filenames"}); + options.allow_unrecognised_options(); + // Parse options the usual way - auto result = options.parse(argc, argv); + cxxopts::ParseResult result; + try { + result = options.parse(argc, argv); + } catch(cxxopts::exceptions::parsing const& e) { + std::cout << options.help() << std::endl; + return 1; + } + + // print usage message if unrecognised options are present + if (result.unmatched().size() > 0) + { + std::cout << options.help() << std::endl; + return 1; + } // display help message if (result.count("help"))