forge/cmd/
geiger.rs

1use clap::{Parser, ValueHint};
2use eyre::Result;
3use foundry_cli::opts::BuildOpts;
4use foundry_config::impl_figment_convert;
5use std::path::PathBuf;
6
7/// CLI arguments for `forge geiger`.
8///
9/// This command is an alias for `forge lint --only-lint unsafe-cheatcode`
10/// and detects usage of unsafe cheat codes in a project and its dependencies.
11#[derive(Clone, Debug, Parser)]
12pub struct GeigerArgs {
13    /// Paths to files or directories to detect.
14    #[arg(
15        value_hint = ValueHint::FilePath,
16        value_name = "PATH",
17        num_args(0..)
18    )]
19    paths: Vec<PathBuf>,
20
21    #[arg(long, hide = true)]
22    check: bool,
23
24    #[arg(long, hide = true)]
25    full: bool,
26
27    #[command(flatten)]
28    build: BuildOpts,
29}
30
31impl_figment_convert!(GeigerArgs, build);
32
33impl GeigerArgs {
34    pub fn run(self) -> Result<()> {
35        // Deprecated flags warnings
36        if self.check {
37            sh_warn!("`--check` is deprecated as it's now the default behavior\n")?;
38        }
39        if self.full {
40            sh_warn!("`--full` is deprecated as reports are not generated anymore\n")?;
41        }
42
43        sh_warn!(
44            "`forge geiger` is just an alias for `forge lint --only-lint unsafe-cheatcode`\n"
45        )?;
46
47        // Convert geiger command to lint command with specific lint filter
48        let lint_args = crate::cmd::lint::LintArgs {
49            paths: self.paths,
50            severity: None,
51            lint: Some(vec!["unsafe-cheatcode".to_string()]),
52            json: false,
53            build: self.build,
54        };
55
56        // Run the lint command with the geiger-specific configuration
57        lint_args.run()
58    }
59}