Skip to content

Commit 999071c

Browse files
committed
fix: Change visible to hidden
1 parent d15c9af commit 999071c

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

clap_complete/src/dynamic/completer.rs

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn complete_arg(
198198
comp.get_content().to_string_lossy()
199199
))
200200
.help(comp.get_help().cloned())
201-
.visible(comp.is_visible())
201+
.hide(comp.is_hide_set())
202202
}),
203203
);
204204
}
@@ -241,7 +241,6 @@ fn complete_arg(
241241
comp.get_content().to_string_lossy()
242242
))
243243
.help(comp.get_help().cloned())
244-
.visible(true)
245244
}),
246245
);
247246
} else if let Some(short) = arg.to_short() {
@@ -271,7 +270,7 @@ fn complete_arg(
271270
comp.get_content().to_string_lossy()
272271
))
273272
.help(comp.get_help().cloned())
274-
.visible(comp.is_visible())
273+
.hide(comp.is_hide_set())
275274
}),
276275
);
277276
} else {
@@ -283,7 +282,7 @@ fn complete_arg(
283282
comp.get_content().to_string_lossy()
284283
))
285284
.help(comp.get_help().cloned())
286-
.visible(comp.is_visible())
285+
.hide(comp.is_hide_set())
287286
},
288287
));
289288
}
@@ -324,8 +323,8 @@ fn complete_arg(
324323
}
325324
}
326325
}
327-
if completions.iter().any(|a| a.is_visible()) {
328-
completions.retain(|a| a.is_visible());
326+
if completions.iter().any(|a| !a.is_hide_set()) {
327+
completions.retain(|a| !a.is_hide_set());
329328
}
330329

331330
Ok(completions)
@@ -346,7 +345,7 @@ fn complete_arg_value(
346345
name.starts_with(value).then(|| {
347346
CompletionCandidate::new(OsString::from(name))
348347
.help(p.get_help().cloned())
349-
.visible(!p.is_hide_set())
348+
.hide(p.is_hide_set())
350349
})
351350
}));
352351
}
@@ -428,20 +427,14 @@ fn complete_path(
428427
let path = entry.path();
429428
let mut suggestion = pathdiff::diff_paths(&path, current_dir).unwrap_or(path);
430429
suggestion.push(""); // Ensure trailing `/`
431-
completions.push(
432-
CompletionCandidate::new(suggestion.as_os_str().to_owned())
433-
.help(None)
434-
.visible(true),
435-
);
430+
completions
431+
.push(CompletionCandidate::new(suggestion.as_os_str().to_owned()).help(None));
436432
} else {
437433
let path = entry.path();
438434
if is_wanted(&path) {
439435
let suggestion = pathdiff::diff_paths(&path, current_dir).unwrap_or(path);
440-
completions.push(
441-
CompletionCandidate::new(suggestion.as_os_str().to_owned())
442-
.help(None)
443-
.visible(true),
444-
);
436+
completions
437+
.push(CompletionCandidate::new(suggestion.as_os_str().to_owned()).help(None));
445438
}
446439
}
447440
}
@@ -476,7 +469,7 @@ fn longs_and_visible_aliases(p: &clap::Command) -> Vec<CompletionCandidate> {
476469
longs.into_iter().map(|s| {
477470
CompletionCandidate::new(format!("--{}", s))
478471
.help(a.get_help().cloned())
479-
.visible(!a.is_hide_set())
472+
.hide(a.is_hide_set())
480473
})
481474
})
482475
})
@@ -494,7 +487,7 @@ fn hidden_longs_aliases(p: &clap::Command) -> Vec<CompletionCandidate> {
494487
longs.into_iter().map(|s| {
495488
CompletionCandidate::new(format!("--{}", s))
496489
.help(a.get_help().cloned())
497-
.visible(false)
490+
.hide(true)
498491
})
499492
})
500493
})
@@ -513,7 +506,7 @@ fn shorts_and_visible_aliases(p: &clap::Command) -> Vec<CompletionCandidate> {
513506
shorts.into_iter().map(|s| {
514507
CompletionCandidate::new(s.to_string())
515508
.help(a.get_help().cloned())
516-
.visible(!a.is_hide_set())
509+
.hide(a.is_hide_set())
517510
})
518511
})
519512
})
@@ -546,12 +539,12 @@ fn subcommands(p: &clap::Command) -> Vec<CompletionCandidate> {
546539
.map(|s| {
547540
CompletionCandidate::new(s.to_string())
548541
.help(sc.get_about().cloned())
549-
.visible(!sc.is_hide_set())
542+
.hide(sc.is_hide_set())
550543
})
551544
.chain(sc.get_aliases().map(|s| {
552545
CompletionCandidate::new(s.to_string())
553546
.help(sc.get_about().cloned())
554-
.visible(false)
547+
.hide(true)
555548
}))
556549
})
557550
.collect()
@@ -667,8 +660,8 @@ pub struct CompletionCandidate {
667660
/// Help message with a completion candidate
668661
help: Option<StyledStr>,
669662

670-
/// Whether the completion candidate is visible
671-
visible: bool,
663+
/// Whether the completion candidate is hidden
664+
hidden: bool,
672665
}
673666

674667
impl CompletionCandidate {
@@ -688,8 +681,8 @@ impl CompletionCandidate {
688681
}
689682

690683
/// Set the visibility of the completion candidate
691-
pub fn visible(mut self, visible: bool) -> Self {
692-
self.visible = visible;
684+
pub fn hide(mut self, hidden: bool) -> Self {
685+
self.hidden = hidden;
693686
self
694687
}
695688

@@ -704,7 +697,7 @@ impl CompletionCandidate {
704697
}
705698

706699
/// Get the visibility of the completion candidate
707-
pub fn is_visible(&self) -> bool {
708-
self.visible
700+
pub fn is_hide_set(&self) -> bool {
701+
self.hidden
709702
}
710703
}

0 commit comments

Comments
 (0)