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, geiger, generate, init::InitArgs, inspect, install::InstallArgs,
5    remappings::RemappingArgs, remove::RemoveArgs, selectors::SelectorsSubcommands, snapshot,
6    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: http://book.getfoundry.sh/reference/forge/forge.html",
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 a smart contract as a script, building transactions that can be sent onchain.
40    Script(ScriptArgs),
41
42    /// Generate coverage reports.
43    Coverage(coverage::CoverageArgs),
44
45    /// Generate Rust bindings for smart contracts.
46    #[command(alias = "bi")]
47    Bind(BindArgs),
48
49    /// Build the project's smart contracts.
50    #[command(visible_aliases = ["b", "compile"])]
51    Build(BuildArgs),
52
53    /// Clone a contract from Etherscan.
54    Clone(CloneArgs),
55
56    /// Update one or multiple dependencies.
57    ///
58    /// If no arguments are provided, then all dependencies are updated.
59    #[command(visible_alias = "u")]
60    Update(update::UpdateArgs),
61
62    /// Install one or multiple dependencies.
63    ///
64    /// If no arguments are provided, then existing dependencies will be installed.
65    #[command(visible_alias = "i")]
66    Install(InstallArgs),
67
68    /// Remove one or multiple dependencies.
69    #[command(visible_alias = "rm")]
70    Remove(RemoveArgs),
71
72    /// Get the automatically inferred remappings for the project.
73    #[command(visible_alias = "re")]
74    Remappings(RemappingArgs),
75
76    /// Verify smart contracts on Etherscan.
77    #[command(visible_alias = "v")]
78    VerifyContract(VerifyArgs),
79
80    /// Check verification status on Etherscan.
81    #[command(visible_alias = "vc")]
82    VerifyCheck(VerifyCheckArgs),
83
84    /// Verify the deployed bytecode against its source on Etherscan.
85    #[command(visible_alias = "vb")]
86    VerifyBytecode(VerifyBytecodeArgs),
87
88    /// Deploy a smart contract.
89    #[command(visible_alias = "c")]
90    Create(CreateArgs),
91
92    /// Create a new Forge project.
93    Init(InitArgs),
94
95    /// Generate shell completions script.
96    #[command(visible_alias = "com")]
97    Completions {
98        #[arg(value_enum)]
99        shell: clap_complete::Shell,
100    },
101
102    /// Generate Fig autocompletion spec.
103    #[command(visible_alias = "fig")]
104    GenerateFigSpec,
105
106    /// Remove the build artifacts and cache directories.
107    #[command(visible_alias = "cl")]
108    Clean {
109        /// The project's root path.
110        ///
111        /// By default root of the Git repository, if in one,
112        /// or the current working directory.
113        #[arg(long, value_hint = ValueHint::DirPath, value_name = "PATH")]
114        root: Option<PathBuf>,
115    },
116
117    /// Manage the Foundry cache.
118    Cache(CacheArgs),
119
120    /// Create a gas snapshot of each test's gas usage.
121    #[command(visible_alias = "s")]
122    Snapshot(snapshot::GasSnapshotArgs),
123
124    /// Display the current config.
125    #[command(visible_alias = "co")]
126    Config(config::ConfigArgs),
127
128    /// Flatten a source file and all of its imports into one file.
129    #[command(visible_alias = "f")]
130    Flatten(flatten::FlattenArgs),
131
132    /// Format Solidity source files.
133    Fmt(FmtArgs),
134
135    /// Get specialized information about a smart contract.
136    #[command(visible_alias = "in")]
137    Inspect(inspect::InspectArgs),
138
139    /// Display a tree visualization of the project's dependency graph.
140    #[command(visible_alias = "tr")]
141    Tree(tree::TreeArgs),
142
143    /// Detects usage of unsafe cheat codes in a project and its dependencies.
144    Geiger(geiger::GeigerArgs),
145
146    /// Generate documentation for the project.
147    Doc(DocArgs),
148
149    /// Function selector utilities.
150    #[command(visible_alias = "se")]
151    Selectors {
152        #[command(subcommand)]
153        command: SelectorsSubcommands,
154    },
155
156    /// Generate scaffold files.
157    Generate(generate::GenerateArgs),
158
159    /// Compiler utilities.
160    Compiler(CompilerArgs),
161
162    /// Soldeer dependency manager.
163    Soldeer(soldeer::SoldeerArgs),
164
165    /// Generate EIP-712 struct encodings for structs from a given file.
166    Eip712(eip712::Eip712Args),
167
168    /// Generate bindings for serialization/deserialization of project structs via JSON cheatcodes.
169    BindJson(bind_json::BindJsonArgs),
170}
171
172#[cfg(test)]
173mod tests {
174    use super::*;
175    use clap::CommandFactory;
176
177    #[test]
178    fn verify_cli() {
179        Forge::command().debug_assert();
180    }
181}