Skip to content

Commit 8aaf704

Browse files
committed
fix(complete): Do not suggest options after "--"
1 parent 4a86fee commit 8aaf704

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

clap_complete/src/engine/complete.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ pub fn complete(
4747
arg.to_value_os(),
4848
);
4949
if cursor == target_cursor {
50-
return complete_arg(&arg, current_cmd, current_dir, pos_index, current_state);
50+
return complete_arg(
51+
&arg,
52+
current_cmd,
53+
current_dir,
54+
pos_index,
55+
is_escaped,
56+
current_state,
57+
);
5158
}
5259

5360
if let Ok(value) = arg.to_value() {
@@ -133,6 +140,7 @@ fn complete_arg(
133140
cmd: &clap::Command,
134141
current_dir: Option<&std::path::Path>,
135142
pos_index: usize,
143+
is_escaped: bool,
136144
state: ParseState<'_>,
137145
) -> Result<Vec<CompletionCandidate>, std::io::Error> {
138146
debug!(
@@ -157,7 +165,9 @@ fn complete_arg(
157165
{
158166
completions.extend(complete_arg_value(arg.to_value(), positional, current_dir));
159167
}
160-
completions.extend(complete_option(arg, cmd, current_dir));
168+
if !is_escaped {
169+
completions.extend(complete_option(arg, cmd, current_dir));
170+
}
161171
}
162172
ParseState::Pos((_, num_arg)) => {
163173
if let Some(positional) = cmd
@@ -183,6 +193,7 @@ fn complete_arg(
183193
cmd,
184194
current_dir,
185195
pos_index,
196+
is_escaped,
186197
ParseState::ValueDone,
187198
)?);
188199
}

clap_complete/tests/testsuite/engine.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ fn suggest_subcommand_positional_after_escape() {
279279
hello-world Say hello to the world
280280
hello-moon
281281
goodbye-world
282-
--help Print help (see more with '--help')
283282
"#]],
284283
);
285284
}
@@ -1055,8 +1054,6 @@ comma,tab
10551054
a_pos
10561055
b_pos
10571056
c_pos
1058-
--delimiter
1059-
--help Print help
10601057
"#]]
10611058
);
10621059

0 commit comments

Comments
 (0)