Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion argh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "README.md"
[dependencies]
argh_shared.workspace = true
argh_derive.workspace = true
rust-fuzzy-search = "0.1.1"
rust-fuzzy-search = { version = "0.1.1", optional = true }

[dev-dependencies]
trybuild = "1.0.63"
Expand Down
14 changes: 12 additions & 2 deletions argh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ pub type SubCommandInfo = argh_shared::SubCommandInfo<'static>;

pub use argh_shared::{ErrorCodeInfo, FlagInfo, FlagInfoKind, Optionality, PositionalInfo};

#[cfg(feature = "rust-fuzzy-search")]
use rust_fuzzy_search::fuzzy_search_best_n;

/// Structured information about the command line arguments.
Expand Down Expand Up @@ -1038,8 +1039,17 @@ fn unrecognized_argument(
return format!("Unrecognized argument: \"{}\"\n", given);
}

let suggestions = fuzzy_search_best_n(given, &available, 1);
format!("Unrecognized argument: \"{}\". Did you mean \"{}\"?\n", given, suggestions[0].0)
#[cfg(feature = "rust-fuzzy-search")]
{
let suggestions = fuzzy_search_best_n(given, &available, 1);
return format!(
"Unrecognized argument: \"{}\". Did you mean \"{}\"?\n",
given, suggestions[0].0
);
}

#[cfg(not(feature = "rust-fuzzy-search"))]
["Unrecognized argument: ", given, "\n"].concat()
}

// `--` or `-` options, including a mutable reference to their value.
Expand Down
3 changes: 3 additions & 0 deletions argh/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,10 @@ mod fuchsia_commandline_tools_rubric {

let e = OneOption::from_args(&["cmdname"], &["--foo=bar"])
.expect_err("Parsing option value using `=` should fail");
#[cfg(feature = "rust-fuzzy-search")]
assert_eq!(e.output, "Unrecognized argument: \"--foo=bar\". Did you mean \"--foo\"?\n");
#[cfg(not(feature = "rust-fuzzy-search"))]
assert_eq!(e.output, "Unrecognized argument: --foo=bar\n");
assert!(e.status.is_err());
}

Expand Down
2 changes: 1 addition & 1 deletion argh_shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn indent_description(line: &mut String) -> bool {
let cur_len = char_len(line);
if cur_len < DESCRIPTION_INDENT {
let num_spaces = DESCRIPTION_INDENT - cur_len;
line.extend(std::iter::repeat(' ').take(num_spaces));
line.extend(std::iter::repeat_n(' ', num_spaces));
true
} else {
false
Expand Down
Loading