forge/cmd/
remove.rs
1use clap::{Parser, ValueHint};
2use eyre::Result;
3use foundry_cli::{
4 opts::Dependency,
5 utils::{Git, LoadConfig},
6};
7use foundry_config::impl_figment_convert_basic;
8use std::path::PathBuf;
9
10#[derive(Clone, Debug, Parser)]
12pub struct RemoveArgs {
13 #[arg(required = true)]
15 dependencies: Vec<Dependency>,
16
17 #[arg(long, value_hint = ValueHint::DirPath, value_name = "PATH")]
22 root: Option<PathBuf>,
23
24 #[arg(short, long)]
26 force: bool,
27}
28impl_figment_convert_basic!(RemoveArgs);
29
30impl RemoveArgs {
31 pub fn run(self) -> Result<()> {
32 let config = self.load_config()?;
33 let (root, paths) = super::update::dependencies_paths(&self.dependencies, &config)?;
34 let git_modules = root.join(".git/modules");
35
36 Git::new(&root).rm(self.force, &paths)?;
38
39 for (Dependency { name, url, tag, .. }, path) in self.dependencies.iter().zip(&paths) {
41 sh_println!("Removing '{name}' in {}, (url: {url:?}, tag: {tag:?})", path.display())?;
42 std::fs::remove_dir_all(git_modules.join(path))?;
43 }
44
45 Ok(())
46 }
47}