Skip to content

Commit b04bf72

Browse files
committed
fix(complete)!: Be consistent in value language
1 parent 0e28259 commit b04bf72

File tree

5 files changed

+27
-31
lines changed

5 files changed

+27
-31
lines changed

clap_complete/src/command/shells.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fi
247247
if i != 0 {
248248
write!(buf, "{}", ifs.as_deref().unwrap_or("\n"))?;
249249
}
250-
write!(buf, "{}", candidate.get_content().to_string_lossy())?;
250+
write!(buf, "{}", candidate.get_value().to_string_lossy())?;
251251
}
252252
Ok(())
253253
}
@@ -341,7 +341,7 @@ set edit:completion:arg-completer[BIN] = { |@words|
341341
if i != 0 {
342342
write!(buf, "{}", ifs.as_deref().unwrap_or("\n"))?;
343343
}
344-
write!(buf, "{}", candidate.get_content().to_string_lossy())?;
344+
write!(buf, "{}", candidate.get_value().to_string_lossy())?;
345345
}
346346
Ok(())
347347
}
@@ -379,7 +379,7 @@ impl CommandCompleter for Fish {
379379
let completions = crate::engine::complete(cmd, args, index, current_dir)?;
380380

381381
for candidate in completions {
382-
write!(buf, "{}", candidate.get_content().to_string_lossy())?;
382+
write!(buf, "{}", candidate.get_value().to_string_lossy())?;
383383
if let Some(help) = candidate.get_help() {
384384
write!(
385385
buf,
@@ -445,7 +445,7 @@ Register-ArgumentCompleter -Native -CommandName {bin} -ScriptBlock {{
445445
let completions = crate::engine::complete(cmd, args, index, current_dir)?;
446446

447447
for candidate in completions {
448-
write!(buf, "{}", candidate.get_content().to_string_lossy())?;
448+
write!(buf, "{}", candidate.get_value().to_string_lossy())?;
449449
if let Some(help) = candidate.get_help() {
450450
write!(
451451
buf,
@@ -522,7 +522,7 @@ compdef _clap_dynamic_completer BIN"#
522522
if i != 0 {
523523
write!(buf, "{}", ifs.as_deref().unwrap_or("\n"))?;
524524
}
525-
write!(buf, "{}", candidate.get_content().to_string_lossy())?;
525+
write!(buf, "{}", candidate.get_value().to_string_lossy())?;
526526
}
527527
Ok(())
528528
}

clap_complete/src/engine/candidate.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ use clap::builder::StyledStr;
66
/// A shell-agnostic completion candidate
77
#[derive(Default, Debug, PartialEq, Eq, PartialOrd, Ord)]
88
pub struct CompletionCandidate {
9-
content: OsString,
9+
value: OsString,
1010
help: Option<StyledStr>,
1111
hidden: bool,
1212
}
1313

1414
impl CompletionCandidate {
1515
/// Create a new completion candidate
16-
pub fn new(content: impl Into<OsString>) -> Self {
17-
let content = content.into();
16+
pub fn new(value: impl Into<OsString>) -> Self {
17+
let value = value.into();
1818
Self {
19-
content,
19+
value,
2020
..Default::default()
2121
}
2222
}
@@ -35,24 +35,24 @@ impl CompletionCandidate {
3535
self
3636
}
3737

38-
/// Add a prefix to the content of completion candidate
38+
/// Add a prefix to the value of completion candidate
3939
///
4040
/// This is generally used for post-process by [`complete`][crate::engine::complete()] for
4141
/// things like pre-pending flags, merging delimiter-separated values, etc.
4242
pub fn add_prefix(mut self, prefix: impl Into<OsString>) -> Self {
43-
let suffix = self.content;
44-
let mut content = prefix.into();
45-
content.push(&suffix);
46-
self.content = content;
43+
let suffix = self.value;
44+
let mut value = prefix.into();
45+
value.push(&suffix);
46+
self.value = value;
4747
self
4848
}
4949
}
5050

5151
/// Reflection API
5252
impl CompletionCandidate {
53-
/// Get the content of the completion candidate
54-
pub fn get_content(&self) -> &OsStr {
55-
&self.content
53+
/// Get the literal value being proposed for completion
54+
pub fn get_value(&self) -> &OsStr {
55+
&self.value
5656
}
5757

5858
/// Get the help message of the completion candidate

clap_complete/src/engine/complete.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,11 @@ fn complete_arg(
150150
}
151151
} else {
152152
completions.extend(longs_and_visible_aliases(cmd).into_iter().filter(
153-
|comp| {
154-
comp.get_content()
155-
.starts_with(format!("--{}", flag).as_str())
156-
},
153+
|comp| comp.get_value().starts_with(format!("--{}", flag).as_str()),
157154
));
158155

159156
completions.extend(hidden_longs_aliases(cmd).into_iter().filter(|comp| {
160-
comp.get_content()
161-
.starts_with(format!("--{}", flag).as_str())
157+
comp.get_value().starts_with(format!("--{}", flag).as_str())
162158
}));
163159
}
164160
}
@@ -352,7 +348,7 @@ fn complete_custom_arg_value(
352348
debug!("complete_custom_arg_value: completer={completer:?}, value={value:?}");
353349

354350
let mut values = completer.candidates();
355-
values.retain(|comp| comp.get_content().starts_with(&value.to_string_lossy()));
351+
values.retain(|comp| comp.get_value().starts_with(&value.to_string_lossy()));
356352
values
357353
}
358354

@@ -365,7 +361,7 @@ fn complete_subcommand(value: &str, cmd: &clap::Command) -> Vec<CompletionCandid
365361

366362
let mut scs = subcommands(cmd)
367363
.into_iter()
368-
.filter(|x| x.get_content().starts_with(value))
364+
.filter(|x| x.get_value().starts_with(value))
369365
.collect::<Vec<_>>();
370366
scs.sort();
371367
scs.dedup();

clap_complete/src/env/shells.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fi
9292
if i != 0 {
9393
write!(buf, "{}", ifs.as_deref().unwrap_or("\n"))?;
9494
}
95-
write!(buf, "{}", candidate.get_content().to_string_lossy())?;
95+
write!(buf, "{}", candidate.get_value().to_string_lossy())?;
9696
}
9797
Ok(())
9898
}
@@ -195,7 +195,7 @@ set edit:completion:arg-completer[BIN] = { |@words|
195195
if i != 0 {
196196
write!(buf, "{}", ifs.as_deref().unwrap_or("\n"))?;
197197
}
198-
write!(buf, "{}", candidate.get_content().to_string_lossy())?;
198+
write!(buf, "{}", candidate.get_value().to_string_lossy())?;
199199
}
200200
Ok(())
201201
}
@@ -240,7 +240,7 @@ impl EnvCompleter for Fish {
240240
let completions = crate::engine::complete(cmd, args, index, current_dir)?;
241241

242242
for candidate in completions {
243-
write!(buf, "{}", candidate.get_content().to_string_lossy())?;
243+
write!(buf, "{}", candidate.get_value().to_string_lossy())?;
244244
if let Some(help) = candidate.get_help() {
245245
write!(
246246
buf,
@@ -313,7 +313,7 @@ Register-ArgumentCompleter -Native -CommandName {bin} -ScriptBlock {{
313313
let completions = crate::engine::complete(cmd, args, index, current_dir)?;
314314

315315
for candidate in completions {
316-
write!(buf, "{}", candidate.get_content().to_string_lossy())?;
316+
write!(buf, "{}", candidate.get_value().to_string_lossy())?;
317317
if let Some(help) = candidate.get_help() {
318318
write!(
319319
buf,
@@ -399,7 +399,7 @@ compdef _clap_dynamic_completer BIN"#
399399
if i != 0 {
400400
write!(buf, "{}", ifs.as_deref().unwrap_or("\n"))?;
401401
}
402-
write!(buf, "{}", candidate.get_content().to_string_lossy())?;
402+
write!(buf, "{}", candidate.get_value().to_string_lossy())?;
403403
}
404404
Ok(())
405405
}

clap_complete/tests/testsuite/engine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ fn complete(cmd: &mut Command, args: impl AsRef<str>, current_dir: Option<&Path>
10061006
.unwrap()
10071007
.into_iter()
10081008
.map(|candidate| {
1009-
let compl = candidate.get_content().to_str().unwrap();
1009+
let compl = candidate.get_value().to_str().unwrap();
10101010
if let Some(help) = candidate.get_help() {
10111011
format!("{compl}\t{help}")
10121012
} else {

0 commit comments

Comments
 (0)