Browse Source

Add a warning if MULTISHELL env var is not in PATH (#295)

Fixes #183
remotes/origin/add-with-shims
Gal Schlezinger 5 years ago committed by GitHub
parent
commit
51c1bb5695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      src/commands/use.rs

29
src/commands/use.rs

@ -25,6 +25,7 @@ impl Command for Use { @@ -25,6 +25,7 @@ impl Command for Use {
fn apply(self, config: &FnmConfig) -> Result<(), Self::Error> {
let multishell_path = config.multishell_path().context(FnmEnvWasNotSourced)?;
warn_if_multishell_path_not_in_path_env_var(&multishell_path, &config);
let all_versions =
installed_versions::list(config.installations_dir()).context(VersionListingError)?;
@ -114,6 +115,32 @@ fn should_install_interactively(requested_version: &UserVersion) -> bool { @@ -114,6 +115,32 @@ fn should_install_interactively(requested_version: &UserVersion) -> bool {
s.trim().to_lowercase() == "y"
}
fn warn_if_multishell_path_not_in_path_env_var(
multishell_path: &std::path::Path,
config: &FnmConfig,
) {
let bin_path = if cfg!(unix) {
multishell_path.join("bin")
} else {
multishell_path.to_path_buf()
};
for path in std::env::split_paths(&std::env::var("PATH").unwrap_or(String::new())) {
if bin_path == path {
return;
}
}
outln!(
config#Error,
"{} {}\n{}\n{}",
"warning:".yellow().bold(),
"The current Node.js path is not on your PATH environment variable.".yellow(),
"Have you set up your shell profile to evaluate `fnm env`?".yellow(),
"Check out our documentation for more information: https://fnm.vercel.app".yellow()
);
}
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("Can't create the symlink: {}", source))]
@ -133,7 +160,7 @@ pub enum Error { @@ -133,7 +160,7 @@ pub enum Error {
#[snafu(display(
"{}\n{}\n{}",
"We can't find the necessary environment variables to replace the Node version.",
" Have you set up your shell profile to evaluate `fnm env`?",
"Have you set up your shell profile to evaluate `fnm env`?",
"Check out our documentation for more information: https://fnm.vercel.app"
))]
FnmEnvWasNotSourced,

Loading…
Cancel
Save