1use clap::{Parser, ValueHint};
2use eyre::Result;
3use foundry_cli::utils::LoadConfig;
4use foundry_config::impl_figment_convert_basic;
5use std::{collections::BTreeMap, path::PathBuf};
6
7#[derive(Clone, Debug, Parser)]
9pub struct RemappingArgs {
10 #[arg(long, value_hint = ValueHint::DirPath, value_name = "PATH")]
15 root: Option<PathBuf>,
16 #[arg(long)]
18 pretty: bool,
19}
20impl_figment_convert_basic!(RemappingArgs);
21
22impl RemappingArgs {
23 pub fn run(self) -> Result<()> {
24 let config = self.load_config()?;
25
26 if self.pretty {
27 let mut groups = BTreeMap::<_, Vec<_>>::new();
28 for remapping in config.remappings {
29 groups.entry(remapping.context.clone()).or_default().push(remapping);
30 }
31 for (group, remappings) in groups {
32 if let Some(group) = group {
33 sh_status!("Context: {group}")?;
34 } else {
35 sh_status!("Global:")?;
36 }
37
38 for remapping in remappings {
39 sh_println!("{remapping}")?;
40 }
41 sh_eprintln!()?;
42 }
43 } else {
44 for remapping in config.remappings {
45 sh_println!("{remapping}")?;
46 }
47 }
48
49 Ok(())
50 }
51}