mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
Merge pull request #5045 from ModProg/fish-dynamic-completions-v3
chore(ci): Verify dynamic completion support
This commit is contained in:
commit
053c778e98
9 changed files with 30 additions and 65 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -73,6 +73,8 @@ jobs:
|
|||
- name: Test (ultra-minimal)
|
||||
if: matrix.build == 'minimal'
|
||||
run: make test-minimal ARGS='--manifest-path Cargo.toml'
|
||||
- name: Test dynamic completions
|
||||
run: cargo test -p clap_complete -F unstable-dynamic
|
||||
check:
|
||||
name: Check
|
||||
runs-on: ubuntu-latest
|
||||
|
|
2
.github/workflows/rust-next.yml
vendored
2
.github/workflows/rust-next.yml
vendored
|
@ -70,3 +70,5 @@ jobs:
|
|||
- name: Test (ultra-minimal)
|
||||
if: matrix.build == 'minimal'
|
||||
run: make test-minimal ARGS='--manifest-path Cargo.toml'
|
||||
- name: Test dynamic completions
|
||||
run: cargo test -p clap_complete -F unstable-dynamic
|
||||
|
|
|
@ -241,7 +241,7 @@ fn complete_path(
|
|||
.flatten()
|
||||
.filter_map(Result::ok)
|
||||
{
|
||||
let raw_file_name = OsString::from(entry.file_name());
|
||||
let raw_file_name = entry.file_name();
|
||||
if !raw_file_name.starts_with(&prefix) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
|
||||
_clap_complete_my_app() {
|
||||
local IFS=$'/013'
|
||||
local SUPPRESS_SPACE=0
|
||||
export _CLAP_COMPLETE_INDEX=${COMP_CWORD}
|
||||
export _CLAP_COMPLETE_COMP_TYPE=${COMP_TYPE}
|
||||
if compopt +o nospace 2> /dev/null; then
|
||||
SUPPRESS_SPACE=1
|
||||
fi
|
||||
if [[ ${SUPPRESS_SPACE} == 1 ]]; then
|
||||
SPACE_ARG="--no-space"
|
||||
export _CLAP_COMPLETE_SPACE=false
|
||||
else
|
||||
SPACE_ARG="--space"
|
||||
export _CLAP_COMPLETE_SPACE=true
|
||||
fi
|
||||
COMPREPLY=( $("my-app" complete --index ${COMP_CWORD} --type ${COMP_TYPE} ${SPACE_ARG} --ifs="$IFS" -- "${COMP_WORDS[@]}") )
|
||||
export _CLAP_COMPLETE_IFS=$'/013'
|
||||
COMPREPLY=( $("my-app" complete --shell bash -- "${COMP_WORDS[@]}") )
|
||||
if [[ $? != 0 ]]; then
|
||||
unset COMPREPLY
|
||||
elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "${COMPREPLY-}" =~ [=/:]$ ]]; then
|
||||
|
|
|
@ -99,13 +99,15 @@ fn value_terminator() {
|
|||
#[cfg(feature = "unstable-dynamic")]
|
||||
#[test]
|
||||
fn register_minimal() {
|
||||
use clap_complete::dynamic::Completer;
|
||||
|
||||
let name = "my-app";
|
||||
let executables = [name];
|
||||
let bin = name;
|
||||
let completer = name;
|
||||
let behavior = clap_complete::dynamic::bash::Behavior::Minimal;
|
||||
|
||||
let mut buf = Vec::new();
|
||||
clap_complete::dynamic::bash::register(name, executables, completer, &behavior, &mut buf)
|
||||
clap_complete::dynamic::shells::Bash
|
||||
.write_registration(name, bin, completer, &mut buf)
|
||||
.unwrap();
|
||||
snapbox::Assert::new()
|
||||
.action_env("SNAPSHOTS")
|
||||
|
|
|
@ -369,7 +369,7 @@ pub fn register_example(name: &str, shell: completest::Shell) {
|
|||
|
||||
runtime.register(name, registration).unwrap();
|
||||
|
||||
snapbox::assert_subset_eq(&home, scratch_path);
|
||||
snapbox::assert_subset_eq(home, scratch_path);
|
||||
|
||||
scratch.close().unwrap();
|
||||
}
|
||||
|
|
|
@ -13,19 +13,10 @@ fn suggest_subcommand_subset() {
|
|||
let args = IntoIterator::into_iter(args)
|
||||
.map(std::ffi::OsString::from)
|
||||
.collect::<Vec<_>>();
|
||||
let comp_type = clap_complete::dynamic::bash::CompType::default();
|
||||
let trailing_space = true;
|
||||
let current_dir = None;
|
||||
|
||||
let completions = clap_complete::dynamic::bash::complete(
|
||||
&mut cmd,
|
||||
args,
|
||||
arg_index,
|
||||
comp_type,
|
||||
trailing_space,
|
||||
current_dir,
|
||||
)
|
||||
.unwrap();
|
||||
let completions =
|
||||
clap_complete::dynamic::complete(&mut cmd, args, arg_index, current_dir).unwrap();
|
||||
let completions = completions
|
||||
.into_iter()
|
||||
.map(|s| s.to_string_lossy().into_owned())
|
||||
|
@ -59,19 +50,10 @@ fn suggest_long_flag_subset() {
|
|||
let args = IntoIterator::into_iter(args)
|
||||
.map(std::ffi::OsString::from)
|
||||
.collect::<Vec<_>>();
|
||||
let comp_type = clap_complete::dynamic::bash::CompType::default();
|
||||
let trailing_space = true;
|
||||
let current_dir = None;
|
||||
|
||||
let completions = clap_complete::dynamic::bash::complete(
|
||||
&mut cmd,
|
||||
args,
|
||||
arg_index,
|
||||
comp_type,
|
||||
trailing_space,
|
||||
current_dir,
|
||||
)
|
||||
.unwrap();
|
||||
let completions =
|
||||
clap_complete::dynamic::complete(&mut cmd, args, arg_index, current_dir).unwrap();
|
||||
let completions = completions
|
||||
.into_iter()
|
||||
.map(|s| s.to_string_lossy().into_owned())
|
||||
|
@ -94,19 +76,10 @@ fn suggest_possible_value_subset() {
|
|||
let args = IntoIterator::into_iter(args)
|
||||
.map(std::ffi::OsString::from)
|
||||
.collect::<Vec<_>>();
|
||||
let comp_type = clap_complete::dynamic::bash::CompType::default();
|
||||
let trailing_space = true;
|
||||
let current_dir = None;
|
||||
|
||||
let completions = clap_complete::dynamic::bash::complete(
|
||||
&mut cmd,
|
||||
args,
|
||||
arg_index,
|
||||
comp_type,
|
||||
trailing_space,
|
||||
current_dir,
|
||||
)
|
||||
.unwrap();
|
||||
let completions =
|
||||
clap_complete::dynamic::complete(&mut cmd, args, arg_index, current_dir).unwrap();
|
||||
let completions = completions
|
||||
.into_iter()
|
||||
.map(|s| s.to_string_lossy().into_owned())
|
||||
|
@ -140,19 +113,10 @@ fn suggest_additional_short_flags() {
|
|||
let args = IntoIterator::into_iter(args)
|
||||
.map(std::ffi::OsString::from)
|
||||
.collect::<Vec<_>>();
|
||||
let comp_type = clap_complete::dynamic::bash::CompType::default();
|
||||
let trailing_space = true;
|
||||
let current_dir = None;
|
||||
|
||||
let completions = clap_complete::dynamic::bash::complete(
|
||||
&mut cmd,
|
||||
args,
|
||||
arg_index,
|
||||
comp_type,
|
||||
trailing_space,
|
||||
current_dir,
|
||||
)
|
||||
.unwrap();
|
||||
let completions =
|
||||
clap_complete::dynamic::complete(&mut cmd, args, arg_index, current_dir).unwrap();
|
||||
let completions = completions
|
||||
.into_iter()
|
||||
.map(|s| s.to_string_lossy().into_owned())
|
||||
|
|
|
@ -441,7 +441,7 @@ Options:
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(feature = "wrap_help"))]
|
||||
#[cfg(feature = "wrap_help")]
|
||||
fn possible_value_wrapped_help() {
|
||||
static WRAPPED_HELP: &str = "\
|
||||
Usage: test [OPTIONS]
|
||||
|
|
|
@ -13,7 +13,7 @@ fn test_vec_of_vec() {
|
|||
Opt {
|
||||
points: vec![vec![1, 2], vec![0, 0]]
|
||||
},
|
||||
Opt::try_parse_from(&["test", "-p", "1", "2", "-p", "0", "0"]).unwrap()
|
||||
Opt::try_parse_from(["test", "-p", "1", "2", "-p", "0", "0"]).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ fn test_vec_vec_empty() {
|
|||
|
||||
assert_eq!(
|
||||
Opt { points: vec![] },
|
||||
Opt::try_parse_from(&["test"]).unwrap()
|
||||
Opt::try_parse_from(["test"]).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ fn test_option_vec_vec() {
|
|||
Opt {
|
||||
points: Some(vec![vec![1, 2], vec![3, 4]])
|
||||
},
|
||||
Opt::try_parse_from(&["test", "-p", "1", "2", "-p", "3", "4"]).unwrap()
|
||||
Opt::try_parse_from(["test", "-p", "1", "2", "-p", "3", "4"]).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -75,8 +75,5 @@ fn test_option_vec_vec_empty() {
|
|||
points: Option<Vec<Vec<i32>>>,
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
Opt { points: None },
|
||||
Opt::try_parse_from(&["test"]).unwrap()
|
||||
);
|
||||
assert_eq!(Opt { points: None }, Opt::try_parse_from(["test"]).unwrap());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue