Browse Source

Allow unsuccessful symlink deletion in `fnm use` (#308)

remotes/origin/add-with-shims
Gal Schlezinger 4 years ago committed by GitHub
parent
commit
ed5a82fd84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/cli.rs
  2. 2
      src/commands/env.rs
  3. 2
      src/commands/install.rs
  4. 10
      src/commands/use.rs
  5. 11
      src/config.rs

8
src/cli.rs

@ -22,6 +22,13 @@ pub enum SubCommand { @@ -22,6 +22,13 @@ pub enum SubCommand {
Use(commands::r#use::Use),
/// Print and set up required environment variables for fnm
///
/// This command generates a series of shell commands that
/// should be evaluated by your shell to create a fnm-ready environment.
///
/// Each shell has its own syntax of evaluating a dynamic expression.
/// For example, evaluating fnm on Bash and Zsh would look like `eval "$(fnm env)"`.
/// In Fish, evaluating would look like `fnm env | source`
#[structopt(name = "env")]
Env(commands::env::Env),
@ -78,6 +85,7 @@ impl SubCommand { @@ -78,6 +85,7 @@ impl SubCommand {
}
}
/// A fast and simple Node.js manager.
#[derive(StructOpt, Debug)]
#[structopt(name = "fnm")]
pub struct Cli {

2
src/commands/env.rs

@ -15,7 +15,7 @@ pub struct Env { @@ -15,7 +15,7 @@ pub struct Env {
#[structopt(possible_values = AVAILABLE_SHELLS)]
shell: Option<Box<dyn Shell>>,
/// Deprecated. This is the default now.
#[structopt(long)]
#[structopt(long, hidden = true)]
multi: bool,
/// Print the script to change Node versions every directory change
#[structopt(long)]

2
src/commands/install.rs

@ -18,7 +18,7 @@ pub struct Install { @@ -18,7 +18,7 @@ pub struct Install {
pub version: Option<UserVersion>,
/// Install latest LTS
#[structopt(long)]
#[structopt(long, conflicts_with = "version")]
pub lts: bool,
}

10
src/commands/use.rs

@ -86,8 +86,12 @@ impl Command for Use { @@ -86,8 +86,12 @@ impl Command for Use {
}
};
fs::remove_symlink_dir(&multishell_path).context(SymlinkingDeletionIssue)?;
fs::symlink_dir(version_path, &multishell_path).context(SymlinkingCreationIssue)?;
let symlink_deletion_result = fs::remove_symlink_dir(&multishell_path);
let symlink_result = fs::symlink_dir(version_path, &multishell_path);
symlink_result
.or(symlink_deletion_result)
.context(SymlinkingCreationIssue)?;
Ok(())
}
@ -145,8 +149,6 @@ fn warn_if_multishell_path_not_in_path_env_var( @@ -145,8 +149,6 @@ fn warn_if_multishell_path_not_in_path_env_var(
pub enum Error {
#[snafu(display("Can't create the symlink: {}", source))]
SymlinkingCreationIssue { source: std::io::Error },
#[snafu(display("Can't delete the symlink: {}", source))]
SymlinkingDeletionIssue { source: std::io::Error },
#[snafu(display("{}", source))]
InstallError { source: <Install as Command>::Error },
#[snafu(display("Can't get locally installed versions: {}", source))]

11
src/config.rs

@ -16,8 +16,15 @@ pub struct FnmConfig { @@ -16,8 +16,15 @@ pub struct FnmConfig {
#[structopt(long = "fnm-dir", env = "FNM_DIR")]
pub base_dir: Option<std::path::PathBuf>,
/// Where the current node version link is stored
#[structopt(long, env = "FNM_MULTISHELL_PATH")]
/// Where the current node version link is stored.
/// This value will be populated automatically by evaluating
/// `fnm env` in your shell profile. Read more about it using `fnm help env`
#[structopt(
long,
env = "FNM_MULTISHELL_PATH",
hide_env_values = true,
hidden = true
)]
multishell_path: Option<std::path::PathBuf>,
/// The log level of fnm commands

Loading…
Cancel
Save