Skip to main content

forge/
opts.rs

1use crate::cmd::{
2    bind::BindArgs, bind_json, build::BuildArgs, cache::CacheArgs, clone::CloneArgs,
3    compiler::CompilerArgs, config, coverage, create::CreateArgs, doc::DocArgs, eip712, flatten,
4    fmt::FmtArgs, fuzz::FuzzArgs, geiger, generate, init::InitArgs, inspect, install::InstallArgs,
5    lint::LintArgs, remappings::RemappingArgs, remove::RemoveArgs, selectors::SelectorsSubcommands,
6    snapshot, soldeer, test, tree, update,
7};
8use clap::{Parser, Subcommand, ValueHint};
9use forge_script::ScriptArgs;
10use forge_verify::{VerifyArgs, VerifyBytecodeArgs, VerifyCheckArgs};
11use foundry_cli::opts::GlobalArgs;
12use foundry_common::version::{LONG_VERSION, SHORT_VERSION};
13use std::path::PathBuf;
14
15/// Build, test, fuzz, debug and deploy Solidity contracts.
16#[derive(Parser)]
17#[command(
18    name = "forge",
19    version = SHORT_VERSION,
20    long_version = LONG_VERSION,
21    after_help = "Find more information in the book: https://getfoundry.sh/forge/overview",
22    next_display_order = None,
23)]
24pub struct Forge {
25    /// Include the global arguments.
26    #[command(flatten)]
27    pub global: GlobalArgs,
28
29    #[command(subcommand)]
30    pub cmd: ForgeSubcommand,
31}
32
33#[derive(Subcommand)]
34pub enum ForgeSubcommand {
35    /// Run the project's tests.
36    #[command(visible_alias = "t")]
37    Test(test::TestArgs),
38
39    /// Run and manage Forge fuzzing corpora.
40    Fuzz(FuzzArgs),
41
42    /// Run a smart contract as a script, building transactions that can be sent onchain.
43    Script(ScriptArgs),
44
45    /// Generate coverage reports.
46    Coverage(coverage::CoverageArgs),
47
48    /// Generate Rust bindings for smart contracts.
49    #[command(alias = "bi")]
50    Bind(BindArgs),
51
52    /// Build the project's smart contracts.
53    #[command(visible_aliases = ["b", "compile"])]
54    Build(BuildArgs),
55
56    /// Clone a contract from Etherscan.
57    Clone(CloneArgs),
58
59    /// Update one or multiple dependencies.
60    ///
61    /// If no arguments are provided, then all dependencies are updated.
62    #[command(visible_alias = "u")]
63    Update(update::UpdateArgs),
64
65    /// Install one or multiple dependencies.
66    ///
67    /// If no arguments are provided, then existing dependencies will be installed.
68    #[command(visible_aliases = ["i", "add"])]
69    Install(InstallArgs),
70
71    /// Remove one or multiple dependencies.
72    #[command(visible_alias = "rm")]
73    Remove(RemoveArgs),
74
75    /// Get the automatically inferred remappings for the project.
76    #[command(visible_alias = "re")]
77    Remappings(RemappingArgs),
78
79    /// Verify smart contracts on Etherscan and Sourcify.
80    #[command(visible_alias = "v")]
81    VerifyContract(VerifyArgs),
82
83    /// Check verification status on the selected verifier.
84    #[command(visible_alias = "vc")]
85    VerifyCheck(VerifyCheckArgs),
86
87    /// Verify the deployed bytecode against its source on Etherscan.
88    #[command(visible_alias = "vb")]
89    VerifyBytecode(VerifyBytecodeArgs),
90
91    /// Deploy a smart contract.
92    #[command(visible_alias = "c")]
93    Create(CreateArgs),
94
95    /// Create a new Forge project.
96    Init(InitArgs),
97
98    /// Generate shell completions script.
99    #[command(visible_alias = "com")]
100    Completions {
101        #[arg(value_enum)]
102        shell: foundry_cli::clap::Shell,
103    },
104
105    /// Remove the build artifacts and cache directories.
106    #[command(visible_alias = "cl")]
107    Clean {
108        /// The project's root path.
109        ///
110        /// By default root of the Git repository, if in one,
111        /// or the current working directory.
112        #[arg(long, value_hint = ValueHint::DirPath, value_name = "PATH")]
113        root: Option<PathBuf>,
114    },
115
116    /// Manage the Foundry cache.
117    Cache(CacheArgs),
118
119    /// Create a gas snapshot of each test's gas usage.
120    #[command(visible_alias = "s")]
121    Snapshot(snapshot::GasSnapshotArgs),
122
123    /// Display the current config.
124    #[command(visible_alias = "co")]
125    Config(config::ConfigArgs),
126
127    /// Flatten a source file and all of its imports into one file.
128    #[command(visible_alias = "f")]
129    Flatten(flatten::FlattenArgs),
130
131    /// Format Solidity source files.
132    Fmt(FmtArgs),
133
134    /// Lint Solidity source files
135    #[command(visible_alias = "l")]
136    Lint(LintArgs),
137
138    /// Get specialized information about a smart contract.
139    #[command(visible_alias = "in")]
140    Inspect(inspect::InspectArgs),
141
142    /// Display a tree visualization of the project's dependency graph.
143    #[command(visible_alias = "tr")]
144    Tree(tree::TreeArgs),
145
146    /// DEPRECATED: Detects usage of unsafe cheat codes in a project and its dependencies.
147    ///
148    /// This is an alias for `forge lint --only-lint unsafe-cheatcode`.
149    Geiger(geiger::GeigerArgs),
150
151    /// Generate documentation for the project.
152    Doc(DocArgs),
153
154    /// Function selector utilities.
155    #[command(visible_alias = "se")]
156    Selectors {
157        #[command(subcommand)]
158        command: SelectorsSubcommands,
159    },
160
161    /// Generate scaffold files.
162    #[command(hide = true)]
163    Generate(generate::GenerateArgs),
164
165    /// Compiler utilities.
166    Compiler(CompilerArgs),
167
168    /// Soldeer dependency manager.
169    Soldeer(soldeer::SoldeerArgs),
170
171    /// Generate EIP-712 struct encodings for structs from a given file.
172    Eip712(eip712::Eip712Args),
173
174    /// Generate bindings for serialization/deserialization of project structs via JSON cheatcodes.
175    BindJson(bind_json::BindJsonArgs),
176}
177
178#[cfg(test)]
179mod tests {
180    use super::*;
181    use clap::CommandFactory;
182
183    #[test]
184    fn verify_cli() {
185        Forge::command().debug_assert();
186    }
187}