mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
test(complete): Register bash dynamic completions
This commit is contained in:
parent
9a6208c795
commit
dc953e95d0
3 changed files with 39 additions and 4 deletions
22
clap_complete/tests/snapshots/home/dynamic/test/bash/.bashrc
Normal file
22
clap_complete/tests/snapshots/home/dynamic/test/bash/.bashrc
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
PS1='% '
|
||||||
|
. /etc/bash_completion
|
||||||
|
|
||||||
|
_clap_complete_test() {
|
||||||
|
export _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||||
|
export _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||||
|
if compopt +o nospace 2> /dev/null; then
|
||||||
|
export _CLAP_COMPLETE_SPACE=false
|
||||||
|
else
|
||||||
|
export _CLAP_COMPLETE_SPACE=true
|
||||||
|
fi
|
||||||
|
export _CLAP_COMPLETE_IFS=$'\013'
|
||||||
|
COMPREPLY=( $("test" complete --shell bash -- "${COMP_WORDS[@]}") )
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
unset COMPREPLY
|
||||||
|
elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
|
||||||
|
compopt -o nospace
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
complete -o nospace -o bashdefault -F _clap_complete_test test
|
||||||
|
|
||||||
|
|
|
@ -161,3 +161,9 @@ fn complete() {
|
||||||
let actual = runtime.complete(input, &term).unwrap();
|
let actual = runtime.complete(input, &term).unwrap();
|
||||||
snapbox::assert_eq(expected, actual);
|
snapbox::assert_eq(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn register_dynamic_completion() {
|
||||||
|
common::register_example("dynamic", "test", completest::Shell::Bash);
|
||||||
|
}
|
||||||
|
|
|
@ -322,10 +322,17 @@ pub fn register_example(context: &str, name: &str, shell: completest::Shell) {
|
||||||
println!("Compiled");
|
println!("Compiled");
|
||||||
let bin_root = bin_path.parent().unwrap().to_owned();
|
let bin_root = bin_path.parent().unwrap().to_owned();
|
||||||
|
|
||||||
let registration = std::process::Command::new(&bin_path)
|
let mut registration = std::process::Command::new(&bin_path);
|
||||||
.arg(format!("--generate={shell_name}"))
|
match context {
|
||||||
.output()
|
"static" => registration.args([format!("--generate={shell_name}")]),
|
||||||
.unwrap();
|
"dynamic" => registration.args([
|
||||||
|
"complete".to_owned(),
|
||||||
|
"--register=-".to_owned(),
|
||||||
|
format!("--shell={shell_name}"),
|
||||||
|
]),
|
||||||
|
_ => unreachable!("unsupported context {}", context),
|
||||||
|
};
|
||||||
|
let registration = registration.output().unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
registration.status.success(),
|
registration.status.success(),
|
||||||
"{}",
|
"{}",
|
||||||
|
|
Loading…
Add table
Reference in a new issue