1use crate::opts::{Anvil, AnvilSubcommand};
2use clap::{CommandFactory, Parser};
3use eyre::Result;
4use foundry_cli::utils;
5
6pub fn run() -> Result<()> {
8 foundry_cli::opts::GlobalArgs::check_markdown_help::<Anvil>();
9
10 let warnings = setup()?;
11
12 let mut args = Anvil::parse();
13 args.global.init()?;
14 for warning in warnings {
15 let _ = foundry_common::sh_warn!("{warning}");
16 }
17 args.node.evm.resolve_rpc_alias();
18
19 run_command(args)
20}
21
22pub fn setup() -> Result<Vec<String>> {
24 let warnings = utils::common_setup();
25
26 Ok(warnings)
27}
28
29pub fn run_command(args: Anvil) -> Result<()> {
31 if let Some(cmd) = &args.cmd {
32 match cmd {
33 AnvilSubcommand::Completions { shell } => {
34 clap_complete::generate(
35 *shell,
36 &mut Anvil::command(),
37 "anvil",
38 &mut std::io::stdout(),
39 );
40 }
41 }
42 return Ok(());
43 }
44
45 let _ = fdlimit::raise_fd_limit();
46 args.global.tokio_runtime().block_on(args.node.run())
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn verify_cli() {
55 Anvil::command().debug_assert();
56 }
57
58 #[test]
59 fn can_parse_help() {
60 let _: Anvil = Anvil::parse_from(["anvil", "--help"]);
61 }
62
63 #[test]
64 fn can_parse_short_version() {
65 let _: Anvil = Anvil::parse_from(["anvil", "-V"]);
66 }
67
68 #[test]
69 fn can_parse_long_version() {
70 let _: Anvil = Anvil::parse_from(["anvil", "--version"]);
71 }
72
73 #[test]
74 fn can_parse_completions() {
75 let args: Anvil = Anvil::parse_from(["anvil", "completions", "bash"]);
76 assert!(matches!(
77 args.cmd,
78 Some(AnvilSubcommand::Completions {
79 shell: foundry_cli::clap::Shell::ClapCompleteShell(clap_complete::Shell::Bash)
80 })
81 ));
82 }
83}