#mean #did #multiple #json #target #clap-style

bin+lib suggestions

提供 clap-style "你可能想要" 建议的最小库

1 个不稳定版本

0.1.1 2022年1月16日
0.1.0 2022年1月16日

1876解析实现

Download history 339/week @ 2024-03-13 380/week @ 2024-03-20 517/week @ 2024-03-27 603/week @ 2024-04-03 946/week @ 2024-04-10 1038/week @ 2024-04-17 1056/week @ 2024-04-24 1306/week @ 2024-05-01 998/week @ 2024-05-08 1606/week @ 2024-05-15 1667/week @ 2024-05-22 1373/week @ 2024-05-29 300/week @ 2024-06-05 699/week @ 2024-06-12 785/week @ 2024-06-19 905/week @ 2024-06-26

2,934 每月下载量

MIT 许可证

12KB
154

suggestions docs [crates.io]](https://crates.org.cn/crates/suggestions)

提供 clap-style "你可能想要" 建议的最小 Rust 库

唯一的依赖项是 strsim.

实现直接从 clap (见此处) 复制。它已被提取为一个库。

示例

let possible_vals = vec!["test", "possible", "values"];
let input = "tst";
let suggestions = suggestions::provide_suggestions(input, &possible_vals);
assert_eq!(suggestions, vec!["test"]);
// We have a convenience function to only pick only a single suggestion, giving `Some` or `None`
let single_suggestion = suggestions::provide_a_suggestion(input, &possible_vals);
assert_eq!(single_suggestion.unwrap(), "test");

多个匹配项

有时可能会有多个(良好的)建议。

考虑以下示例

let possible_vals = vec!["testing", "tempo"];
let input = "teso"; // Sems ambiguous. Maybe multiple suggestions?
let suggestions = suggestions::provide_suggestions(input, &possible_vals);
// The implementation trys to order matches from "best" to "wort"
assert_eq!(suggestions, vec!["testing", "tempo"]);

在这里(provide_a_suggestion)请求单个建议将尝试返回“最佳”的一个。正如你可以想象的那样,这可能与用户的期望不符。因此,最好坚持使用provide_suggesetions

没有匹配项

如果没有合理相似的内容,请求建议将返回 vec![]None

let possible_vals = vec!["testing", "things", "here"];
let input = "--something-completely_different";
assert_eq!(suggestions::provide_a_suggestion(&input, &possible_vals), None)

二进制文件

作为一个如何使用库的示例,提供了一个二进制文件。

它没有额外的依赖项。所需的目标是作为参数提供,并从标准输入读取“可能的字符串”

示例

$ echo "baz\nbar\nfood\nfoz" | suggestions fod
foz food
# Supports multiple targets
$ echo "baz\nbar\nfood\nfoz" | suggestions fod ba
foz food
baz bar
# No matches -> corresponding empty line
$ echo "baz\nbar\nfood\nfoz" | suggestions fod ba
foz food
baz bar

```

```
# Supports outputing as josn (for whatever that's worth)
# echo "baz\nbar\nfood\nfoz" | suggestions --json fod ba nothing-similar
{
  "fod":["foz","food"],
  "ba":["baz","bar"],
  "nothing-similar":[]
}

依赖关系

~43KB