Skip to content

Commit c7157df

Browse files
authored
Merge pull request #5692 from epage/self
fix(complete): Allow completing '.'
2 parents 03d7226 + 84252b7 commit c7157df

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

clap_complete/src/engine/custom.rs

+4
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ pub(crate) fn complete_path(
259259
};
260260
debug!("complete_path: search_root={search_root:?}, prefix={prefix:?}");
261261

262+
if value_os.is_empty() && is_wanted(&search_root) {
263+
completions.push(".".into());
264+
}
265+
262266
for entry in std::fs::read_dir(&search_root)
263267
.ok()
264268
.into_iter()

clap_complete/tests/testsuite/engine.rs

+35
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,41 @@ d_dir/
616616
);
617617
}
618618

619+
#[test]
620+
fn suggest_value_path_dir() {
621+
let testdir = snapbox::dir::DirRoot::mutable_temp().unwrap();
622+
let testdir_path = testdir.path().unwrap();
623+
fs::write(testdir_path.join("a_file"), "").unwrap();
624+
fs::write(testdir_path.join("b_file"), "").unwrap();
625+
fs::create_dir_all(testdir_path.join("c_dir")).unwrap();
626+
fs::create_dir_all(testdir_path.join("d_dir")).unwrap();
627+
628+
let mut cmd = Command::new("dynamic")
629+
.arg(
630+
clap::Arg::new("input")
631+
.long("input")
632+
.short('i')
633+
.add(ArgValueCompleter::new(
634+
PathCompleter::dir().current_dir(testdir_path.to_owned()),
635+
)),
636+
)
637+
.args_conflicts_with_subcommands(true);
638+
639+
assert_data_eq!(
640+
complete!(cmd, "--input [TAB]", current_dir = Some(testdir_path)),
641+
snapbox::str![[r#"
642+
.
643+
c_dir/
644+
d_dir/
645+
"#]],
646+
);
647+
648+
assert_data_eq!(
649+
complete!(cmd, "--input c[TAB]", current_dir = Some(testdir_path)),
650+
snapbox::str!["c_dir/"],
651+
);
652+
}
653+
619654
#[test]
620655
fn suggest_custom_arg_value() {
621656
fn custom_completer() -> Vec<CompletionCandidate> {

0 commit comments

Comments
 (0)