Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow unsuccessful symlink deletion in fnm use #308

Merged
merged 5 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down Expand Up @@ -78,6 +85,7 @@ impl SubCommand {
}
}

/// A fast and simple Node.js manager.
#[derive(StructOpt, Debug)]
#[structopt(name = "fnm")]
pub struct Cli {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Install {
pub version: Option<UserVersion>,

/// Install latest LTS
#[structopt(long)]
#[structopt(long, conflicts_with = "version")]
pub lts: bool,
}

Expand Down
10 changes: 6 additions & 4 deletions src/commands/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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))]
Expand Down
11 changes: 9 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down