Skip to content

Commit

Permalink
Fix subcommand suggestion (#659)
Browse files Browse the repository at this point in the history
* suggest subcommand even with flags/options

* stop subcommand suggestion if subcommand is correct

* use member functions instead of operator overloads

Co-authored-by: Ken Matsui <[email protected]>

* add braces

Co-authored-by: Ken Matsui <[email protected]>

* use i32 instead of int

Co-authored-by: Ken Matsui <[email protected]>

Co-authored-by: Ken Matsui <[email protected]>
  • Loading branch information
wx257osn2 and ken-matsui authored Jul 24, 2022
1 parent 8c761fd commit ec13052
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,18 @@ main(const int argc, char* argv[]) {
.is_err();
} catch (const structopt::exception& e) {
if (argc > 1) {
i32 subcommand_index = 1;
for (; subcommand_index < argc; ++subcommand_index) {
if (argv[subcommand_index][0] != '-') {
break;
}
}

// try correcting typo
if (const auto sugg =
util::lev_distance::find_similar_str(argv[1], command_list)) {
if (const auto sugg = util::lev_distance::find_similar_str(
argv[subcommand_index], command_list
);
sugg.has_value() && sugg.value() != argv[subcommand_index]) {
err_logger->error(
"{}\n"
" --> Did you mean `{}`?\n\n"
Expand Down

0 comments on commit ec13052

Please sign in to comment.