Use new Shell::from_env method in clap_complete

Instead of having an fd specific implementation.
This commit is contained in:
Thayne McCombs 2022-11-07 23:54:00 -07:00
parent 9e88f91c22
commit 2c3e40c9d9
3 changed files with 4 additions and 24 deletions

4
Cargo.lock generated
View File

@ -129,9 +129,9 @@ dependencies = [
[[package]]
name = "clap_complete"
version = "4.0.3"
version = "4.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfe581a2035db4174cdbdc91265e1aba50f381577f0510d0ad36c7bc59cc84a3"
checksum = "96b0fba905b035a30d25c1b585bf1171690712fbb0ad3ac47214963aa4acc36c"
dependencies = [
"clap",
]

View File

@ -50,7 +50,7 @@ normpath = "0.3.2"
chrono = "0.4"
once_cell = "1.15.0"
crossbeam-channel = "0.5.6"
clap_complete = {version = "4.0", optional = true}
clap_complete = {version = "4.0.5", optional = true}
[dependencies.clap]
version = "4.0.12"

View File

@ -673,32 +673,12 @@ impl Opts {
self.gen_completions
.map(|maybe_shell| match maybe_shell {
Some(sh) => Ok(sh),
None => guess_shell(),
None => Shell::from_env().ok_or_else(|| anyhow!("Unable to get shell from environment")),
})
.transpose()
}
}
#[cfg(feature = "completions")]
fn guess_shell() -> anyhow::Result<Shell> {
let env_shell = std::env::var_os("SHELL").map(PathBuf::from);
if let Some(shell) = env_shell
.as_ref()
.and_then(|s| s.file_name())
.and_then(|s| s.to_str())
{
shell
.parse::<Shell>()
.map_err(|_| anyhow!("Unknown shell {}", shell))
} else {
// Assume powershell on windows
#[cfg(windows)]
return Ok(Shell::PowerShell);
#[cfg(not(windows))]
return Err(anyhow!("Unable to get shell from environment"));
}
}
#[derive(Copy, Clone, PartialEq, Eq, ValueEnum)]
pub enum FileType {
#[value(alias = "f")]