aboutsummaryrefslogtreecommitdiff
path: root/examples/example-completion/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/example-completion/src')
-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!();
}