Skip to main content

forge/cmd/
reinit.rs

1use clap::{Parser, ValueHint};
2use eyre::Result;
3use foundry_cli::utils::{CommandUtils, Git, LoadConfig};
4use foundry_config::impl_figment_convert_basic;
5use std::{path::PathBuf, process::Command};
6
7/// CLI arguments for `forge reinit`.
8#[derive(Clone, Debug, Parser)]
9pub struct ReinitArgs {
10    /// The project's root path.
11    ///
12    /// By default root of the Git repository, if in one,
13    /// or the current working directory.
14    #[arg(long, value_hint = ValueHint::DirPath, value_name = "PATH")]
15    root: Option<PathBuf>,
16}
17impl_figment_convert_basic!(ReinitArgs);
18
19impl ReinitArgs {
20    pub fn run(self) -> Result<()> {
21        let config = self.load_config()?;
22        let root = Git::root_of(&config.root)?;
23        let git = Git::new(&root);
24
25        Command::new("git")
26            .current_dir(&root)
27            .args(["submodule", "deinit", "--force", "."])
28            .exec()?;
29        git.submodule_update(false, false, false, true, std::iter::empty::<PathBuf>())
30    }
31}