-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathargs.rs
143 lines (139 loc) · 5.06 KB
/
args.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use crate::{
cmd::{cache::CacheSubcommands, generate::GenerateSubcommands, watch},
opts::{Forge, ForgeSubcommand},
};
use clap::{CommandFactory, Parser};
use clap_complete::generate;
use eyre::Result;
use foundry_cli::{handler, utils};
use foundry_common::shell;
use foundry_evm::inspectors::cheatcodes::{set_execution_context, ForgeContext};
/// Run the `forge` command line interface.
pub fn run() -> Result<()> {
// Initialize the global logger and other utilities.
handler::install();
utils::load_dotenv();
utils::subscriber();
utils::enable_paint();
let args = Forge::parse();
args.global.init()?;
// Set the execution context based on the subcommand.
let context = match &args.cmd {
ForgeSubcommand::Test(_) => ForgeContext::Test,
ForgeSubcommand::Coverage(_) => ForgeContext::Coverage,
ForgeSubcommand::Snapshot(_) => ForgeContext::Snapshot,
ForgeSubcommand::Script(cmd) => {
if cmd.broadcast {
ForgeContext::ScriptBroadcast
} else if cmd.resume {
ForgeContext::ScriptResume
} else {
ForgeContext::ScriptDryRun
}
}
_ => ForgeContext::Unknown,
};
set_execution_context(context);
// Run the subcommand.
match args.cmd {
ForgeSubcommand::Test(cmd) => {
if cmd.is_watch() {
utils::block_on(watch::watch_test(cmd))
} else {
let silent = cmd.junit || shell::is_json();
let outcome = utils::block_on(cmd.run())?;
outcome.ensure_ok(silent)
}
}
ForgeSubcommand::Script(cmd) => utils::block_on(cmd.run_script()),
ForgeSubcommand::Coverage(cmd) => {
if cmd.is_watch() {
utils::block_on(watch::watch_coverage(cmd))
} else {
utils::block_on(cmd.run())
}
}
ForgeSubcommand::Bind(cmd) => cmd.run(),
ForgeSubcommand::Build(cmd) => {
if cmd.is_watch() {
utils::block_on(watch::watch_build(cmd))
} else {
cmd.run().map(drop)
}
}
ForgeSubcommand::VerifyContract(args) => utils::block_on(args.run()),
ForgeSubcommand::VerifyCheck(args) => utils::block_on(args.run()),
ForgeSubcommand::VerifyBytecode(cmd) => utils::block_on(cmd.run()),
ForgeSubcommand::Clone(cmd) => utils::block_on(cmd.run()),
ForgeSubcommand::Cache(cmd) => match cmd.sub {
CacheSubcommands::Clean(cmd) => cmd.run(),
CacheSubcommands::Ls(cmd) => cmd.run(),
},
ForgeSubcommand::Create(cmd) => utils::block_on(cmd.run()),
ForgeSubcommand::Update(cmd) => cmd.run(),
ForgeSubcommand::Install(cmd) => cmd.run(),
ForgeSubcommand::Remove(cmd) => cmd.run(),
ForgeSubcommand::Remappings(cmd) => cmd.run(),
ForgeSubcommand::Init(cmd) => cmd.run(),
ForgeSubcommand::Completions { shell } => {
generate(shell, &mut Forge::command(), "forge", &mut std::io::stdout());
Ok(())
}
ForgeSubcommand::GenerateFigSpec => {
clap_complete::generate(
clap_complete_fig::Fig,
&mut Forge::command(),
"forge",
&mut std::io::stdout(),
);
Ok(())
}
ForgeSubcommand::Clean { root } => {
let config = utils::load_config_with_root(root.as_deref())?;
let project = config.project()?;
config.cleanup(&project)?;
Ok(())
}
ForgeSubcommand::Snapshot(cmd) => {
if cmd.is_watch() {
utils::block_on(watch::watch_gas_snapshot(cmd))
} else {
utils::block_on(cmd.run())
}
}
ForgeSubcommand::Fmt(cmd) => {
if cmd.is_watch() {
utils::block_on(watch::watch_fmt(cmd))
} else {
cmd.run()
}
}
ForgeSubcommand::Config(cmd) => cmd.run(),
ForgeSubcommand::Flatten(cmd) => cmd.run(),
ForgeSubcommand::Inspect(cmd) => cmd.run(),
ForgeSubcommand::Tree(cmd) => cmd.run(),
ForgeSubcommand::Geiger(cmd) => {
let n = cmd.run()?;
if n > 0 {
std::process::exit(n as i32);
}
Ok(())
}
ForgeSubcommand::Doc(cmd) => {
if cmd.is_watch() {
utils::block_on(watch::watch_doc(cmd))
} else {
utils::block_on(cmd.run())?;
Ok(())
}
}
ForgeSubcommand::Selectors { command } => utils::block_on(command.run()),
ForgeSubcommand::Generate(cmd) => match cmd.sub {
GenerateSubcommands::Test(cmd) => cmd.run(),
},
ForgeSubcommand::Compiler(cmd) => cmd.run(),
ForgeSubcommand::Soldeer(cmd) => utils::block_on(cmd.run()),
ForgeSubcommand::Eip712(cmd) => cmd.run(),
ForgeSubcommand::BindJson(cmd) => cmd.run(),
}
}