mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
feat(complete): Add DirPath support in bash
This commit is contained in:
parent
3a222def22
commit
e25b1abddf
4 changed files with 21 additions and 6 deletions
|
@ -170,6 +170,7 @@ fn option_details_for_path(cmd: &Command, path: &str) -> String {
|
||||||
for o in p.get_opts() {
|
for o in p.get_opts() {
|
||||||
let compopt = match o.get_value_hint() {
|
let compopt = match o.get_value_hint() {
|
||||||
ValueHint::FilePath => Some("compopt -o filenames"),
|
ValueHint::FilePath => Some("compopt -o filenames"),
|
||||||
|
ValueHint::DirPath => Some("compopt -o plusdirs"),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -229,6 +230,8 @@ fn vals_for(o: &Arg) -> String {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(" ")
|
.join(" ")
|
||||||
)
|
)
|
||||||
|
} else if o.get_value_hint() == ValueHint::DirPath {
|
||||||
|
String::from("") // should be empty to avoid duplicate candidates
|
||||||
} else if o.get_value_hint() == ValueHint::Other {
|
} else if o.get_value_hint() == ValueHint::Other {
|
||||||
String::from("\"${cur}\"")
|
String::from("\"${cur}\"")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -567,11 +567,17 @@ _exhaustive() {
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--dir)
|
--dir)
|
||||||
COMPREPLY=($(compgen -f "${cur}"))
|
COMPREPLY=()
|
||||||
|
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
|
||||||
|
compopt -o plusdirs
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
-d)
|
-d)
|
||||||
COMPREPLY=($(compgen -f "${cur}"))
|
COMPREPLY=()
|
||||||
|
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
|
||||||
|
compopt -o plusdirs
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--exe)
|
--exe)
|
||||||
|
|
|
@ -60,11 +60,17 @@ _my-app() {
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--dir)
|
--dir)
|
||||||
COMPREPLY=($(compgen -f "${cur}"))
|
COMPREPLY=()
|
||||||
|
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
|
||||||
|
compopt -o plusdirs
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
-d)
|
-d)
|
||||||
COMPREPLY=($(compgen -f "${cur}"))
|
COMPREPLY=()
|
||||||
|
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
|
||||||
|
compopt -o plusdirs
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--exe)
|
--exe)
|
||||||
|
|
|
@ -200,8 +200,8 @@ fn complete() {
|
||||||
);
|
);
|
||||||
let actual = runtime.complete(input.as_str(), &term).unwrap();
|
let actual = runtime.complete(input.as_str(), &term).unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
actual.contains("a_file")
|
!actual.contains("a_file")
|
||||||
&& actual.contains("b_file")
|
&& !actual.contains("b_file")
|
||||||
&& actual.contains("c_dir")
|
&& actual.contains("c_dir")
|
||||||
&& actual.contains("d_dir"),
|
&& actual.contains("d_dir"),
|
||||||
"Actual output:\n{}",
|
"Actual output:\n{}",
|
||||||
|
|
Loading…
Add table
Reference in a new issue