Skip to content

Commit

Permalink
change: don't allow uninstalling the active version by default (#93)
Browse files Browse the repository at this point in the history
This is the inverse of the old behavior where the active version is removed by default, which can be prevented by using the --no-used flag. But now, the active version is not removed by default and but can be overridden by the --force flag.
  • Loading branch information
numToStr authored Sep 11, 2021
1 parent 584df01 commit e271488
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,19 @@ snm install lts/fermium

- `snm uninstall [version|alias]` : Removes the installed Nodejs

> If given an alias like `ten` or `lts-fermium` then it will remove the version which the alias is pointing at and all the aliases which are pointing to the same version.
> Also, uninstalling a version will throw an error, if multiple installation is found in the same semver range
> If given an alias like `ten` or `lts-fermium` then it will remove the version which the alias is pointing at and all the aliases which are pointing to the same version. Also, uninstalling a version will throw an error, if multiple installation is found in the same semver range or if the provided version/alias is active, add `--force` flag to override this behavior.
```sh
# Following command will remove 14.x.x installation
snm uninstall 14

# Following command will download the most recent lts/fermium release
# Following command will remove the lts/fermium release
snm uninstall lts/fermium
# or snm uninstall lts-fermium
# or snm rm lts-fermium

# Add --force flag to forcefully remove the active version
snm uninstall --force 16
```

- `snm use [version]` : Change Nodejs version, Supports `.nvmrc` and `.node-version`
Expand Down
10 changes: 5 additions & 5 deletions src/commands/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub struct UnInstall {
/// Semver, Alias or Lts codename that needs to be removed
version: UserVersion,

/// Don't remove if the version is currently active.
#[clap(short = 'N', long)]
no_active: bool,
/// Forcefully remove the active version
#[clap(short, long)]
force: bool,
}

impl super::Command for UnInstall {
Expand Down Expand Up @@ -54,9 +54,9 @@ impl super::Command for UnInstall {
// Checking whether the version is currently active or not
let is_default = aliases.iter().any(|x| *x == UserAlias::ACTIVE);

if is_default && self.no_active {
if is_default && !self.force {
anyhow::bail!(
"Unable to uninstall. Version {} is currently active!",
"Unable to uninstall! Version {} is currently active. Add --force to override this behavior",
style(version).bold()
);
}
Expand Down

0 comments on commit e271488

Please sign in to comment.