From 9b071f4804c35027dd718a12b277a439e4a1cb32 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Sat, 3 May 2025 05:22:42 -0700 Subject: [PATCH] clean up code and comments --- examples/close_match.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/examples/close_match.cpp b/examples/close_match.cpp index a8100939..3f3779bf 100644 --- a/examples/close_match.cpp +++ b/examples/close_match.cpp @@ -67,25 +67,20 @@ void addSubcommandCloseMatchDetection(CLI::App *app, std::size_t minDistance = 3 app->allow_extras(true); // generate a list of subcommand names auto subs = app->get_subcommands(nullptr); - std::vector list; + CLI::results_t list; for(const auto *sub : subs) { if(!sub->get_name().empty()) { - list.push_back(sub->get_name()); + list.emplace_back(sub->get_name()); } - auto aliases = sub->get_aliases(); + const auto &aliases = sub->get_aliases(); if(!aliases.empty()) { list.insert(list.end(), aliases.begin(), aliases.end()); } } // add a callback that runs before a final callback and loops over the remaining arguments for subcommands app->parse_complete_callback([app, minDistance, list = std::move(list)]() { - auto extras = app->remaining(); - if(extras.empty()) { - return; - } - - for(auto &extra : extras) { - if(extra.front() != '-') { + for(auto &extra : app->remaining()) { + if(!extra.empty() && extra.front() != '-') { auto closest = findClosestMatch(extra, list); if(closest.second <= minDistance) { std::cout << "unmatched command \"" << extra << "\", closest match is " << closest.first << "\n"; @@ -101,7 +96,7 @@ void addSubcommandCloseMatchDetection(CLI::App *app, std::size_t minDistance = 3 int main(int argc, const char *argv[]) { int value{0}; - CLI::App app{"cose string App"}; + CLI::App app{"App for testing prefix matching and close string matching"}; // turn on prefix matching app.allow_subcommand_prefix_matching(); app.add_option("-v", value, "value");