From 9c6ef3e0570e5f36d7e16e8c82f687a2c4813b5d Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 26 Jul 2024 14:22:56 -0500 Subject: [PATCH] refactor: Resolve deprecations --- clap_complete/src/dynamic/shells/bash.rs | 3 ++- clap_complete/src/dynamic/shells/elvish.rs | 5 +++-- clap_complete/src/dynamic/shells/fish.rs | 6 ++++-- clap_complete/src/dynamic/shells/zsh.rs | 6 ++++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/clap_complete/src/dynamic/shells/bash.rs b/clap_complete/src/dynamic/shells/bash.rs index d01a932b..ca6d791f 100644 --- a/clap_complete/src/dynamic/shells/bash.rs +++ b/clap_complete/src/dynamic/shells/bash.rs @@ -23,7 +23,8 @@ impl crate::dynamic::Completer for Bash { let mut upper_name = escaped_name.clone(); upper_name.make_ascii_uppercase(); - let completer = shlex::quote(completer); + let completer = + shlex::try_quote(completer).unwrap_or(std::borrow::Cow::Borrowed(completer)); let script = r#" _clap_complete_NAME() { diff --git a/clap_complete/src/dynamic/shells/elvish.rs b/clap_complete/src/dynamic/shells/elvish.rs index 2568af58..52767a65 100644 --- a/clap_complete/src/dynamic/shells/elvish.rs +++ b/clap_complete/src/dynamic/shells/elvish.rs @@ -13,8 +13,9 @@ impl crate::dynamic::Completer for Elvish { completer: &str, buf: &mut dyn std::io::Write, ) -> Result<(), std::io::Error> { - let bin = shlex::quote(bin); - let completer = shlex::quote(completer); + let bin = shlex::try_quote(bin).unwrap_or(std::borrow::Cow::Borrowed(bin)); + let completer = + shlex::try_quote(completer).unwrap_or(std::borrow::Cow::Borrowed(completer)); let script = r#" set edit:completion:arg-completer[BIN] = { |@words| diff --git a/clap_complete/src/dynamic/shells/fish.rs b/clap_complete/src/dynamic/shells/fish.rs index 269539e0..c3ae1dba 100644 --- a/clap_complete/src/dynamic/shells/fish.rs +++ b/clap_complete/src/dynamic/shells/fish.rs @@ -13,8 +13,10 @@ impl crate::dynamic::Completer for Fish { completer: &str, buf: &mut dyn std::io::Write, ) -> Result<(), std::io::Error> { - let bin = shlex::quote(bin); - let completer = shlex::quote(completer); + let bin = shlex::try_quote(bin).unwrap_or(std::borrow::Cow::Borrowed(bin)); + let completer = + shlex::try_quote(completer).unwrap_or(std::borrow::Cow::Borrowed(completer)); + writeln!( buf, r#"complete -x -c {bin} -a "("'{completer}'" complete --shell fish -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))""# diff --git a/clap_complete/src/dynamic/shells/zsh.rs b/clap_complete/src/dynamic/shells/zsh.rs index 4326cd16..326d29ce 100644 --- a/clap_complete/src/dynamic/shells/zsh.rs +++ b/clap_complete/src/dynamic/shells/zsh.rs @@ -13,8 +13,10 @@ impl crate::dynamic::Completer for Zsh { completer: &str, buf: &mut dyn std::io::Write, ) -> Result<(), std::io::Error> { - let bin = shlex::quote(bin); - let completer = shlex::quote(completer); + let bin = shlex::try_quote(bin).unwrap_or(std::borrow::Cow::Borrowed(bin)); + let completer = + shlex::try_quote(completer).unwrap_or(std::borrow::Cow::Borrowed(completer)); + let script = r#"#compdef BIN function _clap_dynamic_completer() { export _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)