|
|
|
@ -1,7 +1,8 @@
@@ -1,7 +1,8 @@
|
|
|
|
|
use super::command::Command; |
|
|
|
|
use crate::cli::Cli; |
|
|
|
|
use crate::config::FnmConfig; |
|
|
|
|
use crate::shell::infer_shell; |
|
|
|
|
use crate::shell::{infer_shell, AVAILABLE_SHELLS}; |
|
|
|
|
use snafu::{OptionExt, Snafu}; |
|
|
|
|
use structopt::clap::Shell; |
|
|
|
|
use structopt::StructOpt; |
|
|
|
|
|
|
|
|
@ -17,11 +18,31 @@ impl Command for Completions {
@@ -17,11 +18,31 @@ impl Command for Completions {
|
|
|
|
|
|
|
|
|
|
fn apply(self, _config: &FnmConfig) -> Result<(), Self::Error> { |
|
|
|
|
let mut stdio = std::io::stdout(); |
|
|
|
|
let shell = self.shell.unwrap_or_else(|| infer_shell().into()); |
|
|
|
|
let shell = self |
|
|
|
|
.shell |
|
|
|
|
.or_else(|| infer_shell().map(Into::into)) |
|
|
|
|
.context(CantInferShell)?; |
|
|
|
|
Cli::clap().gen_completions_to(env!("CARGO_PKG_NAME"), shell, &mut stdio); |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(snafu::Snafu, Debug)] |
|
|
|
|
pub enum Error {} |
|
|
|
|
#[derive(Snafu, Debug)] |
|
|
|
|
pub enum Error { |
|
|
|
|
#[snafu(display(
|
|
|
|
|
"{}\n{}\n{}\n{}", |
|
|
|
|
"Can't infer shell!", |
|
|
|
|
"fnm can't infer your shell based on the process tree.", |
|
|
|
|
"Maybe it is unsupported? we support the following shells:", |
|
|
|
|
shells_as_string() |
|
|
|
|
))] |
|
|
|
|
CantInferShell, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn shells_as_string() -> String { |
|
|
|
|
AVAILABLE_SHELLS |
|
|
|
|
.iter() |
|
|
|
|
.map(|x| format!("* {}", x)) |
|
|
|
|
.collect::<Vec<_>>() |
|
|
|
|
.join("\n") |
|
|
|
|
} |
|
|
|
|