wapm_cli/commands/
uninstall.rs1use crate::config::Config;
2use crate::dataflow;
3use structopt::StructOpt;
4use thiserror::Error;
5
6#[derive(Clone, Debug, Error)]
7pub enum Error {
8 #[error("Packages may only be uninstalled by the package name.")]
9 NoAtSignAllowed,
10}
11
12#[derive(StructOpt, Debug)]
13pub struct UninstallOpt {
14 pub package: String,
15 #[structopt(short = "g", long = "global")]
17 pub global: bool,
18}
19
20pub fn uninstall(options: UninstallOpt) -> anyhow::Result<()> {
21 let dir = match options.global {
22 true => Config::get_globals_directory()?,
23 false => Config::get_current_dir()?,
24 };
25 let uninstalled_package_names = vec![options.package.as_str()];
26
27 if options.package.contains('@') {
29 return Err(Error::NoAtSignAllowed.into());
30 }
31
32 let result = dataflow::update(vec![], uninstalled_package_names, dir)?;
36
37 if !result {
38 info!("Package \"{}\" is not installed.", options.package);
39 } else {
40 info!("Package \"{}\" uninstalled.", options.package);
41 }
42
43 Ok(())
44}