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, lint::LintArgs,
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: 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 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_aliases = ["i", "add"])]
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: foundry_cli::clap::Shell,
100    },
101
102    /// Remove the build artifacts and cache directories.
103    #[command(visible_alias = "cl")]
104    Clean {
105        /// The project's root path.
106        ///
107        /// By default root of the Git repository, if in one,
108        /// or the current working directory.
109        #[arg(long, value_hint = ValueHint::DirPath, value_name = "PATH")]
110        root: Option<PathBuf>,
111    },
112
113    /// Manage the Foundry cache.
114    Cache(CacheArgs),
115
116    /// Create a gas snapshot of each test's gas usage.
117    #[command(visible_alias = "s")]
118    Snapshot(snapshot::GasSnapshotArgs),
119
120    /// Display the current config.
121    #[command(visible_alias = "co")]
122    Config(config::ConfigArgs),
123
124    /// Flatten a source file and all of its imports into one file.
125    #[command(visible_alias = "f")]
126    Flatten(flatten::FlattenArgs),
127
128    /// Format Solidity source files.
129    Fmt(FmtArgs),
130
131    /// Lint Solidity source files
132    #[command(visible_alias = "l")]
133    Lint(LintArgs),
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    /// DEPRECATED: Detects usage of unsafe cheat codes in a project and its dependencies.
144    ///
145    /// This is an alias for `forge lint --only-lint unsafe-cheatcode`.
146    Geiger(geiger::GeigerArgs),
147
148    /// Generate documentation for the project.
149    Doc(DocArgs),
150
151    /// Function selector utilities.
152    #[command(visible_alias = "se")]
153    Selectors {
154        #[command(subcommand)]
155        command: SelectorsSubcommands,
156    },
157
158    /// Generate scaffold files.
159    #[command(hide = true)]
160    Generate(generate::GenerateArgs),
161
162    /// Compiler utilities.
163    Compiler(CompilerArgs),
164
165    /// Soldeer dependency manager.
166    Soldeer(soldeer::SoldeerArgs),
167
168    /// Generate EIP-712 struct encodings for structs from a given file.
169    Eip712(eip712::Eip712Args),
170
171    /// Generate bindings for serialization/deserialization of project structs via JSON cheatcodes.
172    BindJson(bind_json::BindJsonArgs),
173}
174
175#[cfg(test)]
176mod tests {
177    use super::*;
178    use clap::CommandFactory;
179
180    #[test]
181    fn verify_cli() {
182        Forge::command().debug_assert();
183    }
184}