1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-04 22:23:52 +00:00

update some code and change the levenshteinDistance to only work with C++14 or higher

This commit is contained in:
Philip Top 2025-05-02 08:50:43 -07:00
parent 94f08d9c20
commit 7bc28a9a69
2 changed files with 6 additions and 2 deletions

View File

@ -250,6 +250,7 @@ set_property(TEST retired_retired_test3 PROPERTY PASS_REGULAR_EXPRESSION "WARNIN
set_property(TEST retired_deprecated PROPERTY PASS_REGULAR_EXPRESSION "deprecated.*not_deprecated") set_property(TEST retired_deprecated PROPERTY PASS_REGULAR_EXPRESSION "deprecated.*not_deprecated")
if(CMAKE_CXX_STANDARD GREATER 13)
add_cli_exe(close_match close_match.cpp) add_cli_exe(close_match close_match.cpp)
add_test(NAME close_match_test COMMAND close_match i) add_test(NAME close_match_test COMMAND close_match i)
@ -264,7 +265,7 @@ set_property(TEST close_match_test2 PROPERTY PASS_REGULAR_EXPRESSION "upgrade")
set_property(TEST close_match_test3 PROPERTY PASS_REGULAR_EXPRESSION "remove") set_property(TEST close_match_test3 PROPERTY PASS_REGULAR_EXPRESSION "remove")
set_property(TEST close_match_test4 PROPERTY PASS_REGULAR_EXPRESSION "closest match is upgrade") set_property(TEST close_match_test4 PROPERTY PASS_REGULAR_EXPRESSION "closest match is upgrade")
endif()
#-------------------------------------------- #--------------------------------------------
add_cli_exe(custom_parse custom_parse.cpp) add_cli_exe(custom_parse custom_parse.cpp)
add_test(NAME cp_test COMMAND custom_parse --dv 1.7) add_test(NAME cp_test COMMAND custom_parse --dv 1.7)

View File

@ -13,6 +13,9 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <algorithm>
//only works with C++14 or higher
// Levenshtein distance function code generated by chatgpt/copilot // Levenshtein distance function code generated by chatgpt/copilot
std::size_t levenshteinDistance(const std::string &s1, const std::string &s2) { std::size_t levenshteinDistance(const std::string &s1, const std::string &s2) {
@ -75,7 +78,7 @@ void addSubcommandCloseMatchDetection(CLI::App *app, std::size_t minDistance = 3
} }
} }
// add a callback that runs before a final callback and loops over the remaining arguments for subcommands // add a callback that runs before a final callback and loops over the remaining arguments for subcommands
app->parse_complete_callback([&app, minDistance, list]() { app->parse_complete_callback([&app, minDistance,list=std::move(list)]() {
auto extras = app->remaining(); auto extras = app->remaining();
if(extras.empty()) { if(extras.empty()) {
return; return;