aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-04-12 01:06:24 +0800
committer魏曹先生 <1992414357@qq.com>2026-04-12 01:06:24 +0800
commit7c496151f571b872da523f4c46369751be6f4ca1 (patch)
treee71d2aeb7a16f38996b9d68fe77259269ef25c8f /examples
parent5e10b03acb0312155d0d76e06d366bcf76cb9f27 (diff)
Add ShellContext helper methods for completion logic
Diffstat (limited to 'examples')
-rw-r--r--examples/example-completion/src/main.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/examples/example-completion/src/main.rs b/examples/example-completion/src/main.rs
index 06a0969..cbbb7a8 100644
--- a/examples/example-completion/src/main.rs
+++ b/examples/example-completion/src/main.rs
@@ -36,20 +36,21 @@ dispatcher!("fruit", FruitCommand => FruitEntry);
#[completion(FruitEntry)]
fn comp_fruit_command(ctx: &ShellContext) -> Suggest {
- if ctx.current_word.starts_with("-") {
- return suggest! {
- "--name": "Fruit name",
- "--type": "Fruit type"
- };
- }
- if ctx.previous_word == "--name" {
+ if ctx.filling_argument_first("--name") {
return suggest!();
}
- if ctx.previous_word == "--type" {
+ if ctx.filling_argument_first("--type") {
return suggest! {
"apple", "banana"
};
}
+ if ctx.typing_argument() {
+ return suggest! {
+ "--name": "Fruit name",
+ "--type": "Fruit type"
+ }
+ .strip_typed_argument(ctx);
+ }
return suggest!();
}