Skip to content

Commit e271488

Browse files
authored
change: don't allow uninstalling the active version by default (#93)
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.
1 parent 584df01 commit e271488

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,19 @@ snm install lts/fermium
154154

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

157-
> 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.
158-
> Also, uninstalling a version will throw an error, if multiple installation is found in the same semver range
157+
> 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.
159158
160159
```sh
161160
# Following command will remove 14.x.x installation
162161
snm uninstall 14
163162

164-
# Following command will download the most recent lts/fermium release
163+
# Following command will remove the lts/fermium release
165164
snm uninstall lts/fermium
166165
# or snm uninstall lts-fermium
167166
# or snm rm lts-fermium
167+
168+
# Add --force flag to forcefully remove the active version
169+
snm uninstall --force 16
168170
```
169171

170172
- `snm use [version]` : Change Nodejs version, Supports `.nvmrc` and `.node-version`

src/commands/uninstall.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ pub struct UnInstall {
1313
/// Semver, Alias or Lts codename that needs to be removed
1414
version: UserVersion,
1515

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

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

57-
if is_default && self.no_active {
57+
if is_default && !self.force {
5858
anyhow::bail!(
59-
"Unable to uninstall. Version {} is currently active!",
59+
"Unable to uninstall! Version {} is currently active. Add --force to override this behavior",
6060
style(version).bold()
6161
);
6262
}

0 commit comments

Comments
 (0)