From 085058cfffa03663839b946153faf58860aed9ef Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 12 Aug 2024 16:17:25 -0400 Subject: feat: deno remove (#24952) Co-authored-by: Satya Rohith --- cli/args/flags.rs | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'cli/args') diff --git a/cli/args/flags.rs b/cli/args/flags.rs index c6bb90430..b9908f413 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -83,6 +83,11 @@ pub struct AddFlags { pub packages: Vec, } +#[derive(Clone, Debug, Default, Eq, PartialEq)] +pub struct RemoveFlags { + pub packages: Vec, +} + #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct BenchFlags { pub files: FileFlags, @@ -428,6 +433,7 @@ pub struct HelpFlags { #[derive(Clone, Debug, Eq, PartialEq)] pub enum DenoSubcommand { Add(AddFlags), + Remove(RemoveFlags), Bench(BenchFlags), Bundle(BundleFlags), Cache(CacheFlags), @@ -1216,6 +1222,7 @@ pub fn flags_from_vec(args: Vec) -> clap::error::Result { if let Some((subcommand, mut m)) = matches.remove_subcommand() { match subcommand.as_str() { "add" => add_parse(&mut flags, &mut m), + "remove" => remove_parse(&mut flags, &mut m), "bench" => bench_parse(&mut flags, &mut m), "bundle" => bundle_parse(&mut flags, &mut m), "cache" => cache_parse(&mut flags, &mut m), @@ -1442,6 +1449,7 @@ pub fn clap_root() -> Command { .defer(|cmd| { let cmd = cmd .subcommand(add_subcommand()) + .subcommand(remove_subcommand()) .subcommand(bench_subcommand()) .subcommand(bundle_subcommand()) .subcommand(cache_subcommand()) @@ -1515,6 +1523,31 @@ You can add multiple dependencies at once: }) } +fn remove_subcommand() -> Command { + Command::new("remove") + .alias("rm") + .about("Remove dependencies") + .long_about( + "Remove dependencies from the configuration file. + + deno remove @std/path + +You can remove multiple dependencies at once: + + deno remove @std/path @std/assert +", + ) + .defer(|cmd| { + cmd.arg( + Arg::new("packages") + .help("List of packages to remove") + .required(true) + .num_args(1..) + .action(ArgAction::Append), + ) + }) +} + fn bench_subcommand() -> Command { Command::new("bench") .about( @@ -3726,6 +3759,12 @@ fn add_parse_inner( AddFlags { packages } } +fn remove_parse(flags: &mut Flags, matches: &mut ArgMatches) { + flags.subcommand = DenoSubcommand::Remove(RemoveFlags { + packages: matches.remove_many::("packages").unwrap().collect(), + }); +} + fn bench_parse(flags: &mut Flags, matches: &mut ArgMatches) { flags.type_check_mode = TypeCheckMode::Local; @@ -10247,6 +10286,35 @@ mod tests { ); } + #[test] + fn remove_subcommand() { + let r = flags_from_vec(svec!["deno", "remove"]); + r.unwrap_err(); + + let r = flags_from_vec(svec!["deno", "remove", "@david/which"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Remove(RemoveFlags { + packages: svec!["@david/which"], + }), + ..Flags::default() + } + ); + + let r = + flags_from_vec(svec!["deno", "remove", "@david/which", "@luca/hello"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Remove(RemoveFlags { + packages: svec!["@david/which", "@luca/hello"], + }), + ..Flags::default() + } + ); + } + #[test] fn run_with_frozen_lockfile() { let cases = [ -- cgit v1.2.3