forge/cmd/
config.rs

1use super::build::BuildArgs;
2use clap::Parser;
3use eyre::Result;
4use foundry_cli::utils::LoadConfig;
5use foundry_common::{evm::EvmArgs, shell};
6use foundry_config::fix::fix_tomls;
7
8foundry_config::impl_figment_convert!(ConfigArgs, build, evm);
9
10/// CLI arguments for `forge config`.
11#[derive(Clone, Debug, Parser)]
12pub struct ConfigArgs {
13    /// Print only a basic set of the currently set config values.
14    #[arg(long)]
15    basic: bool,
16
17    /// Attempt to fix any configuration warnings.
18    #[arg(long)]
19    fix: bool,
20
21    // support nested build arguments
22    #[command(flatten)]
23    build: BuildArgs,
24
25    #[command(flatten)]
26    evm: EvmArgs,
27}
28
29impl ConfigArgs {
30    pub fn run(self) -> Result<()> {
31        if self.fix {
32            for warning in fix_tomls() {
33                sh_warn!("{warning}")?;
34            }
35            return Ok(())
36        }
37
38        let config = self
39            .load_config_unsanitized()?
40            .normalized_optimizer_settings()
41            // we explicitly normalize the version, so mimic the behavior when invoking solc
42            .normalized_evm_version();
43
44        let s = if self.basic {
45            let config = config.into_basic();
46            if shell::is_json() {
47                serde_json::to_string_pretty(&config)?
48            } else {
49                config.to_string_pretty()?
50            }
51        } else if shell::is_json() {
52            serde_json::to_string_pretty(&config)?
53        } else {
54            config.to_string_pretty()?
55        };
56
57        sh_println!("{s}")?;
58        Ok(())
59    }
60}