diff options
author | Sylvain Cau <sylvaincau31@gmail.com> | 2021-09-30 23:38:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-30 11:38:07 -0400 |
commit | ee2e25fba76a3d25df9d0d5d8d4d0286be915043 (patch) | |
tree | 209010c1d1fd4501ae84a00df9a4002dfa5fae48 /cli/flags.rs | |
parent | f602d63f48067851716d46184746ce26b2e674ba (diff) |
feat(cli/uninstall): add uninstall command (#12209)
Diffstat (limited to 'cli/flags.rs')
-rw-r--r-- | cli/flags.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index 208bfdca8..aaff45388 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -111,6 +111,12 @@ pub struct InstallFlags { } #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +pub struct UninstallFlags { + pub name: String, + pub root: Option<PathBuf>, +} + +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct LintFlags { pub files: Vec<PathBuf>, pub ignore: Vec<PathBuf>, @@ -166,6 +172,7 @@ pub enum DenoSubcommand { Fmt(FmtFlags), Info(InfoFlags), Install(InstallFlags), + Uninstall(UninstallFlags), Lsp, Lint(LintFlags), Repl(ReplFlags), @@ -428,6 +435,8 @@ pub fn flags_from_vec(args: Vec<String>) -> clap::Result<Flags> { bundle_parse(&mut flags, m); } else if let Some(m) = matches.subcommand_matches("install") { install_parse(&mut flags, m); + } else if let Some(m) = matches.subcommand_matches("uninstall") { + uninstall_parse(&mut flags, m); } else if let Some(m) = matches.subcommand_matches("completions") { completions_parse(&mut flags, m); } else if let Some(m) = matches.subcommand_matches("test") { @@ -499,6 +508,7 @@ If the flag is set, restrict these messages to errors.", .subcommand(fmt_subcommand()) .subcommand(info_subcommand()) .subcommand(install_subcommand()) + .subcommand(uninstall_subcommand()) .subcommand(lsp_subcommand()) .subcommand(lint_subcommand()) .subcommand(repl_subcommand()) @@ -995,6 +1005,36 @@ The installation root is determined, in order of precedence: These must be added to the path manually if required.") } +fn uninstall_subcommand<'a, 'b>() -> App<'a, 'b> { + SubCommand::with_name("uninstall") + .setting(AppSettings::TrailingVarArg) + .arg( + Arg::with_name("name") + .required(true) + .multiple(false) + .allow_hyphen_values(true)) + .arg( + Arg::with_name("root") + .long("root") + .help("Installation root") + .takes_value(true) + .multiple(false)) + .about("Uninstall a script previously installed with deno install") + .long_about( + "Uninstalls an executable script in the installation root's bin directory. + + deno uninstall serve + +To change the installation root, use --root: + + deno uninstall --root /usr/local serve + +The installation root is determined, in order of precedence: + - --root option + - DENO_INSTALL_ROOT environment variable + - $HOME/.deno") +} + fn lsp_subcommand<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name("lsp") .about("Start the language server") @@ -1896,6 +1936,18 @@ fn install_parse(flags: &mut Flags, matches: &clap::ArgMatches) { }); } +fn uninstall_parse(flags: &mut Flags, matches: &clap::ArgMatches) { + let root = if matches.is_present("root") { + let install_root = matches.value_of("root").unwrap(); + Some(PathBuf::from(install_root)) + } else { + None + }; + + let name = matches.value_of("name").unwrap().to_string(); + flags.subcommand = DenoSubcommand::Uninstall(UninstallFlags { name, root }); +} + fn lsp_parse(flags: &mut Flags, _matches: &clap::ArgMatches) { flags.subcommand = DenoSubcommand::Lsp; } |