mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-07 23:33:52 +00:00
style: pre-commit.ci fixes
This commit is contained in:
parent
2175dc6c57
commit
7c4a4d555f
@ -13,7 +13,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
||||
// Levenshtein distance function code generated by chatgpt
|
||||
std::size_t levenshteinDistance(const std::string &s1, const std::string &s2) {
|
||||
size_t len1 = s1.size(), len2 = s2.size();
|
||||
@ -38,10 +37,9 @@ std::size_t levenshteinDistance(const std::string &s1, const std::string &s2) {
|
||||
return dp[len1][len2];
|
||||
}
|
||||
|
||||
|
||||
// Finds the closest string from a list (modified from chat gpt code)
|
||||
std::pair<std::string, std::size_t>
|
||||
findClosestMatch(const std::string &input, const std::vector<std::string> &candidates) {
|
||||
std::pair<std::string, std::size_t> findClosestMatch(const std::string &input,
|
||||
const std::vector<std::string> &candidates) {
|
||||
std::string closest;
|
||||
std::size_t minDistance = (std::numeric_limits<std::size_t>::max)();
|
||||
for(const auto &candidate : candidates) {
|
||||
@ -55,7 +53,7 @@ findClosestMatch(const std::string &input, const std::vector<std::string> &candi
|
||||
return {closest, minDistance};
|
||||
}
|
||||
|
||||
void addCloseMatchDetection(CLI::App *app, std::size_t minDistance=3) {
|
||||
void addCloseMatchDetection(CLI::App *app, std::size_t minDistance = 3) {
|
||||
app->allow_extras(true);
|
||||
|
||||
app->parse_complete_callback([&app, minDistance]() {
|
||||
@ -92,7 +90,7 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
int value{0};
|
||||
CLI::App app{"cose string App"};
|
||||
//turn on prefix matching
|
||||
// turn on prefix matching
|
||||
app.allow_subcommand_prefix_matching();
|
||||
app.add_option("-v", value, "value");
|
||||
|
||||
@ -100,7 +98,7 @@ int main(int argc, const char *argv[]) {
|
||||
app.add_subcommand("upgrade", "");
|
||||
app.add_subcommand("remove", "");
|
||||
app.add_subcommand("test", "");
|
||||
addCloseMatchDetection(&app,5);
|
||||
addCloseMatchDetection(&app, 5);
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ class App {
|
||||
|
||||
/// Special private constructor for subcommand
|
||||
App(std::string app_description, std::string app_name, App *parent);
|
||||
|
||||
|
||||
public:
|
||||
/// @name Basic
|
||||
///@{
|
||||
@ -1236,7 +1236,8 @@ class App {
|
||||
CLI11_NODISCARD std::string get_display_name(bool with_aliases = false) const;
|
||||
|
||||
/// Check the name, case-insensitive and underscore insensitive if set
|
||||
/// @return 0 if no match, 1 or higher if there is a match (2 or more is the character difference with prefix matching enabled)
|
||||
/// @return 0 if no match, 1 or higher if there is a match (2 or more is the character difference with prefix
|
||||
/// matching enabled)
|
||||
CLI11_NODISCARD int check_name(std::string name_to_check) const;
|
||||
|
||||
/// Get the groups available directly from this option (in order)
|
||||
|
@ -57,7 +57,7 @@ CLI11_INLINE App::App(std::string app_description, std::string app_name, App *pa
|
||||
formatter_ = parent_->formatter_;
|
||||
config_formatter_ = parent_->config_formatter_;
|
||||
require_subcommand_max_ = parent_->require_subcommand_max_;
|
||||
allow_prefix_matching_=parent_->allow_prefix_matching_;
|
||||
allow_prefix_matching_ = parent_->allow_prefix_matching_;
|
||||
}
|
||||
}
|
||||
|
||||
@ -908,11 +908,9 @@ CLI11_NODISCARD CLI11_INLINE int App::check_name(std::string name_to_check) cons
|
||||
if(local_name == name_to_check) {
|
||||
return 1;
|
||||
}
|
||||
if (allow_prefix_matching_ && name_to_check.size()<local_name.size())
|
||||
{
|
||||
if (local_name.compare(0, name_to_check.size(), name_to_check) == 0)
|
||||
{
|
||||
return static_cast<int>(local_name.size()-name_to_check.size()+1);
|
||||
if(allow_prefix_matching_ && name_to_check.size() < local_name.size()) {
|
||||
if(local_name.compare(0, name_to_check.size(), name_to_check) == 0) {
|
||||
return static_cast<int>(local_name.size() - name_to_check.size() + 1);
|
||||
}
|
||||
}
|
||||
for(std::string les : aliases_) { // NOLINT(performance-for-range-copy)
|
||||
@ -925,11 +923,9 @@ CLI11_NODISCARD CLI11_INLINE int App::check_name(std::string name_to_check) cons
|
||||
if(les == name_to_check) {
|
||||
return 1;
|
||||
}
|
||||
if (allow_prefix_matching_ && name_to_check.size()<les.size())
|
||||
{
|
||||
if (les.compare(0, name_to_check.size(), name_to_check) == 0)
|
||||
{
|
||||
return static_cast<int>(les.size()-name_to_check.size()+1);
|
||||
if(allow_prefix_matching_ && name_to_check.size() < les.size()) {
|
||||
if(les.compare(0, name_to_check.size(), name_to_check) == 0) {
|
||||
return static_cast<int>(les.size() - name_to_check.size() + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1843,32 +1839,28 @@ App::_find_subcommand(const std::string &subc_name, bool ignore_disabled, bool i
|
||||
if(com->get_name().empty()) {
|
||||
auto *subc = com->_find_subcommand(subc_name, ignore_disabled, ignore_used);
|
||||
if(subc != nullptr) {
|
||||
if (bcom != nullptr)
|
||||
{
|
||||
if(bcom != nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
bcom=subc;
|
||||
if (!allow_prefix_matching_) {
|
||||
bcom = subc;
|
||||
if(!allow_prefix_matching_) {
|
||||
return bcom;
|
||||
}
|
||||
}
|
||||
}
|
||||
auto res=com->check_name(subc_name);
|
||||
if(res!=0) {
|
||||
if ((!*com) || !ignore_used) {
|
||||
if (res == 1)
|
||||
{
|
||||
auto res = com->check_name(subc_name);
|
||||
if(res != 0) {
|
||||
if((!*com) || !ignore_used) {
|
||||
if(res == 1) {
|
||||
return com.get();
|
||||
}
|
||||
if (bcom != nullptr)
|
||||
{
|
||||
if(bcom != nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
bcom=com.get();
|
||||
if (!allow_prefix_matching_) {
|
||||
bcom = com.get();
|
||||
if(!allow_prefix_matching_) {
|
||||
return bcom;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +206,6 @@ TEST_CASE_METHOD(TApp, "subcommandPrefixMultiple", "[subcom]") {
|
||||
|
||||
args = {"sub_"};
|
||||
CHECK_THROWS_AS(run(), CLI::ExtrasError);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(TApp, "RequiredAndSubcommands", "[subcom]") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user