瀏覽代碼

Clean up did-you-mean handling for argument_parser

default_compile_flags
vector-of-bool 3 年之前
父節點
當前提交
e7136b6b0b
共有 1 個檔案被更改,包括 11 行新增17 行删除
  1. +11
    -17
      src/debate/argument_parser.cpp

+ 11
- 17
src/debate/argument_parser.cpp 查看文件

@@ -52,30 +52,24 @@ struct parse_engine {
std::optional<std::string> find_nearest_arg_spelling(std::string_view given) const noexcept {
std::vector<std::string> candidates;
// Only match arguments of the corrent type
auto given_long = given.starts_with("--");
auto has_dash = given.starts_with("-");
auto parser = bottom_parser;
auto parser = bottom_parser;
while (parser) {
for (auto& arg : parser->arguments()) {
if (given_long) {
for (auto& l : arg.long_spellings) {
candidates.push_back("--" + l);
}
for (auto& l : arg.long_spellings) {
candidates.push_back("--" + l);
}
if (has_dash) {
for (auto& s : arg.short_spellings) {
candidates.push_back("-" + s);
}
}
if (!has_dash && parser->subparsers() && parser == bottom_parser) {
auto&& grp = *parser->subparsers();
for (auto& p : grp._p_subparsers) {
candidates.push_back(p.name);
}
for (auto& s : arg.short_spellings) {
candidates.push_back("-" + s);
}
}
parser = parser->parent().pointer();
}
if (bottom_parser->subparsers()) {
auto&& grp = *bottom_parser->subparsers();
for (auto& p : grp._p_subparsers) {
candidates.push_back(p.name);
}
}
return dds::did_you_mean(given, candidates);
}


Loading…
取消
儲存