Skip to content

Commit 16ec529

Browse files
committed
fix(cli/uninstall): arg '-g' can't be used with additional packages
1 parent 1a95522 commit 16ec529

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

cli/args/flags.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ pub struct JupyterFlags {
288288

289289
#[derive(Clone, Debug, Eq, PartialEq)]
290290
pub struct UninstallFlagsGlobal {
291-
pub name: String,
291+
pub packages: Vec<String>,
292292
pub root: Option<String>,
293293
}
294294

@@ -2876,7 +2876,6 @@ The installation root is determined, in order of precedence:
28762876
.arg(
28772877
Arg::new("additional-packages")
28782878
.help("List of additional packages to remove")
2879-
.conflicts_with("global")
28802879
.num_args(1..)
28812880
.action(ArgAction::Append)
28822881
)
@@ -5189,19 +5188,19 @@ fn jupyter_parse(flags: &mut Flags, matches: &mut ArgMatches) {
51895188

51905189
fn uninstall_parse(flags: &mut Flags, matches: &mut ArgMatches) {
51915190
let name = matches.remove_one::<String>("name-or-package").unwrap();
5191+
let packages: Vec<_> = vec![name]
5192+
.into_iter()
5193+
.chain(
5194+
matches
5195+
.remove_many::<String>("additional-packages")
5196+
.unwrap_or_default(),
5197+
)
5198+
.collect();
51925199

51935200
let kind = if matches.get_flag("global") {
51945201
let root = matches.remove_one::<String>("root");
5195-
UninstallKind::Global(UninstallFlagsGlobal { name, root })
5202+
UninstallKind::Global(UninstallFlagsGlobal { packages, root })
51965203
} else {
5197-
let packages: Vec<_> = vec![name]
5198-
.into_iter()
5199-
.chain(
5200-
matches
5201-
.remove_many::<String>("additional-packages")
5202-
.unwrap_or_default(),
5203-
)
5204-
.collect();
52055204
UninstallKind::Local(RemoveFlags { packages })
52065205
};
52075206

@@ -8916,7 +8915,7 @@ mod tests {
89168915
Flags {
89178916
subcommand: DenoSubcommand::Uninstall(UninstallFlags {
89188917
kind: UninstallKind::Global(UninstallFlagsGlobal {
8919-
name: "file_server".to_string(),
8918+
packages: vec!["file_server".to_string()],
89208919
root: None,
89218920
}),
89228921
}),
@@ -8937,7 +8936,7 @@ mod tests {
89378936
Flags {
89388937
subcommand: DenoSubcommand::Uninstall(UninstallFlags {
89398938
kind: UninstallKind::Global(UninstallFlagsGlobal {
8940-
name: "file_server".to_string(),
8939+
packages: vec!["file_server".to_string()],
89418940
root: Some("/user/foo/bar".to_string()),
89428941
}),
89438942
}),

cli/tools/installer.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -245,31 +245,31 @@ pub async fn uninstall(
245245
}
246246
}
247247

248-
let file_path = installation_dir.join(&uninstall_flags.name);
248+
for package_name in &uninstall_flags.packages {
249+
let file_path = installation_dir.join(package_name);
249250

250-
let mut removed = remove_file_if_exists(&file_path)?;
251+
let mut removed = remove_file_if_exists(&file_path)?;
251252

252-
if cfg!(windows) {
253-
let file_path = file_path.with_extension("cmd");
254-
removed |= remove_file_if_exists(&file_path)?;
255-
}
253+
if cfg!(windows) {
254+
let file_path = file_path.with_extension("cmd");
255+
removed |= remove_file_if_exists(&file_path)?;
256+
}
256257

257-
if !removed {
258-
return Err(anyhow!(
259-
"No installation found for {}",
260-
uninstall_flags.name
261-
));
262-
}
258+
if !removed {
259+
return Err(anyhow!("No installation found for {}", package_name));
260+
}
261+
262+
// There might be some extra files to delete
263+
// Note: tsconfig.json is legacy. We renamed it to deno.json.
264+
// Remove cleaning it up after January 2024
265+
for ext in ["tsconfig.json", "deno.json", "lock.json"] {
266+
let file_path = file_path.with_extension(ext);
267+
remove_file_if_exists(&file_path)?;
268+
}
263269

264-
// There might be some extra files to delete
265-
// Note: tsconfig.json is legacy. We renamed it to deno.json.
266-
// Remove cleaning it up after January 2024
267-
for ext in ["tsconfig.json", "deno.json", "lock.json"] {
268-
let file_path = file_path.with_extension(ext);
269-
remove_file_if_exists(&file_path)?;
270+
log::info!("✅ Successfully uninstalled {}", package_name);
270271
}
271272

272-
log::info!("✅ Successfully uninstalled {}", uninstall_flags.name);
273273
Ok(())
274274
}
275275

@@ -1611,7 +1611,7 @@ mod tests {
16111611
Default::default(),
16121612
UninstallFlags {
16131613
kind: UninstallKind::Global(UninstallFlagsGlobal {
1614-
name: "echo_test".to_string(),
1614+
packages: vec!["echo_test".to_string()],
16151615
root: Some(temp_dir.path().to_string()),
16161616
}),
16171617
},

0 commit comments

Comments
 (0)