diff options
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r-- | cli/args/flags.rs | 68 |
1 files changed, 68 insertions, 0 deletions
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 @@ -84,6 +84,11 @@ pub struct AddFlags { } #[derive(Clone, Debug, Default, Eq, PartialEq)] +pub struct RemoveFlags { + pub packages: Vec<String>, +} + +#[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct BenchFlags { pub files: FileFlags, pub filter: Option<String>, @@ -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<OsString>) -> clap::error::Result<Flags> { 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::<String>("packages").unwrap().collect(), + }); +} + fn bench_parse(flags: &mut Flags, matches: &mut ArgMatches) { flags.type_check_mode = TypeCheckMode::Local; @@ -10248,6 +10287,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 = [ (Some("--frozen"), true), |