aboutsummaryrefslogtreecommitdiff
path: root/examples/example-completion/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-17 04:05:41 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-17 04:05:41 +0800
commitaa251efb87b561f62266628f06ad341253fbbdc5 (patch)
tree7d2cc2f34f3e4a7282d8d6f0ec0f5ae4bfc87002 /examples/example-completion/src
parentc23c590330af83afb6e146bcd9b0a274b3689d22 (diff)
refactor!: remove legacy parser feature and migrate to picker
The legacy `parser` feature and its module tree (`mingling::parser`, `Argument`, `Picker`, `Pickable`, etc.) have been fully removed and replaced by the `picker` feature powered by `arg-picker`. BREAKING CHANGE: Remove `parser` feature and use `picker` instead. Migration guide: Replace `features = ["parser"]` with `features = ["picker"]` and update API usage per the provided table.
Diffstat (limited to 'examples/example-completion/src')
-rw-r--r--examples/example-completion/src/main.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/examples/example-completion/src/main.rs b/examples/example-completion/src/main.rs
index 7de41f6..d363697 100644
--- a/examples/example-completion/src/main.rs
+++ b/examples/example-completion/src/main.rs
@@ -74,18 +74,22 @@ fn complete_greet_entry(ctx: &ShellContext) -> Suggest {
}
// When the user is typing `--repeat`
- if ctx.filling_argument(["-r", "--repeat"]) {
+ if ctx.previous_word == "-r" || ctx.previous_word == "--repeat" {
return suggest! {}; // Don't suggest anything
}
// When the user is typing `-`
- if ctx.typing_argument() {
- return suggest! {
+ if ctx.current_word.starts_with('-') {
+ // Remove arguments that have already been typed by the user
+ let typed: Vec<&str> = ctx.all_words.iter().map(String::as_str).collect();
+ let mut set = suggest! {
"-r": "Number of repetitions",
"--repeat": "Number of repetitions",
+ };
+ if let Suggest::Suggest(items) = &mut set {
+ items.retain(|item| !typed.contains(&item.suggest().as_str()));
}
- // Remove arguments that have already been typed by the user
- .strip_typed_argument(ctx);
+ return set;
}
// Otherwise, suggest nothing
@@ -102,9 +106,9 @@ pack!(ResultName = (u8, String));
#[chain]
fn handle_greet(args: EntryGreet) -> Next {
let result: ResultName = args
- .pick_or(["-r", "--repeat"], 1)
- .pick_or((), "World")
- .unpack()
+ .pick_or(&arg![repeat: u8, 'r'], || 1)
+ .pick_or(&arg![String], || "World".to_string())
+ .unwrap()
.into();
result.into()
}