summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThayne McCombs <astrothayne@gmail.com>2022-11-07 23:54:00 -0700
committerThayne McCombs <astrothayne@gmail.com>2022-11-11 02:09:41 -0700
commit2c3e40c9d9627141a4fd884823db52dabf4463cb (patch)
tree30226552cd3b0ff30c8e8afea5fad5309fe5e212
parent9e88f91c2275449a95f06fd33b2be5c18e358e7f (diff)
Use new Shell::from_env method in clap_complete
Instead of having an fd specific implementation.
-rw-r--r--Cargo.lock4
-rw-r--r--Cargo.toml2
-rw-r--r--src/cli.rs22
3 files changed, 4 insertions, 24 deletions
diff --git a/Cargo.lock b/Cargo.lock
index aa9df73..af137b4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
]
diff --git a/Cargo.toml b/Cargo.toml
index 878c1c5..6f57249 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"
diff --git a/src/cli.rs b/src/cli.rs
index 465473f..004b0cb 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -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")]