Skip to content

Commit d8f102a

Browse files
authored
Merge pull request #5732 from epage/consistent
docs(complete): Clarify CompleteEnv's Shell trait
2 parents 5ca60e9 + c92fca3 commit d8f102a

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

clap_complete/src/env/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ pub trait EnvCompleter {
295295
/// Write the `buf` the logic needed for calling into `<VAR>=<shell> <cmd> --`, passing needed
296296
/// arguments to [`EnvCompleter::write_complete`] through the environment.
297297
///
298+
/// - `var`: see [`CompleteEnv::var`]
299+
/// - `name`: an identifier to use in the script
300+
/// - `bin`: the binary being completed
301+
/// - `completer`: the command to run to generate completions
302+
///
298303
/// **WARNING:** There are no stability guarantees between the call to
299304
/// [`EnvCompleter::write_complete`] that this generates and actually calling [`EnvCompleter::write_complete`].
300305
/// Caching the results of this call may result in invalid or no completions to be generated.

clap_complete/src/env/shells.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ impl EnvCompleter for Bash {
2323
buf: &mut dyn std::io::Write,
2424
) -> Result<(), std::io::Error> {
2525
let escaped_name = name.replace('-', "_");
26-
let mut upper_name = escaped_name.clone();
27-
upper_name.make_ascii_uppercase();
2826

2927
let completer =
3028
shlex::try_quote(completer).unwrap_or(std::borrow::Cow::Borrowed(completer));
@@ -61,7 +59,6 @@ fi
6159
.replace("NAME", &escaped_name)
6260
.replace("BIN", bin)
6361
.replace("COMPLETER", &completer)
64-
.replace("UPPER", &upper_name)
6562
.replace("VAR", var);
6663

6764
writeln!(buf, "{script}")?;
@@ -341,17 +338,18 @@ impl EnvCompleter for Zsh {
341338
fn write_registration(
342339
&self,
343340
var: &str,
344-
_name: &str,
341+
name: &str,
345342
bin: &str,
346343
completer: &str,
347344
buf: &mut dyn std::io::Write,
348345
) -> Result<(), std::io::Error> {
346+
let escaped_name = name.replace('-', "_");
349347
let bin = shlex::try_quote(bin).unwrap_or(std::borrow::Cow::Borrowed(bin));
350348
let completer =
351349
shlex::try_quote(completer).unwrap_or(std::borrow::Cow::Borrowed(completer));
352350

353351
let script = r#"#compdef BIN
354-
function _clap_dynamic_completer() {
352+
function _clap_dynamic_completer_NAME() {
355353
local _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)
356354
local _CLAP_IFS=$'\n'
357355
@@ -367,7 +365,8 @@ function _clap_dynamic_completer() {
367365
fi
368366
}
369367
370-
compdef _clap_dynamic_completer BIN"#
368+
compdef _clap_dynamic_completer_NAME BIN"#
369+
.replace("NAME", &escaped_name)
371370
.replace("COMPLETER", &completer)
372371
.replace("BIN", &bin)
373372
.replace("VAR", var);

clap_complete/tests/snapshots/home/dynamic-env/exhaustive/zsh/zsh/_exhaustive

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#compdef exhaustive
2-
function _clap_dynamic_completer() {
2+
function _clap_dynamic_completer_exhaustive() {
33
local _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)
44
local _CLAP_IFS=$'\n'
55

@@ -15,4 +15,4 @@ function _clap_dynamic_completer() {
1515
fi
1616
}
1717

18-
compdef _clap_dynamic_completer exhaustive
18+
compdef _clap_dynamic_completer_exhaustive exhaustive

0 commit comments

Comments
 (0)