Skip to content

Commit 8b36d4d

Browse files
zerosnacksrplusq
authored andcommitted
feat(common::shell): add global verbosity level (-vvv) flag replacing --verbose (foundry-rs#9273)
* remove --verbose, prefer output mode, introduce verbosity level (-vvv) * remove leftover * fix arg * add ability to set verbosity level * fix tests * remove evm args specific verbosity arg in favor of global arg due to Clap limitation * revert test modifications from foundry-rs#9244 for TestArgs, simply pass + flatten ShellOpts in args * in lieu of a context specific help document the verbosity levels of the EVM as an example * format comment, update tests * fix clippy
1 parent 4b4d81c commit 8b36d4d

File tree

12 files changed

+152
-180
lines changed

12 files changed

+152
-180
lines changed

crates/cast/bin/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ pub enum CastSubcommand {
793793
who: Option<String>,
794794

795795
/// Perform a reverse lookup to verify that the name is correct.
796-
#[arg(long, short)]
796+
#[arg(long)]
797797
verify: bool,
798798

799799
#[command(flatten)]
@@ -807,7 +807,7 @@ pub enum CastSubcommand {
807807
who: Option<Address>,
808808

809809
/// Perform a normal lookup to verify that the address is correct.
810-
#[arg(long, short)]
810+
#[arg(long)]
811811
verify: bool,
812812

813813
#[command(flatten)]

crates/cast/bin/cmd/run.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use foundry_cli::{
88
opts::{EtherscanOpts, RpcOpts},
99
utils::{handle_traces, init_progress, TraceResult},
1010
};
11-
use foundry_common::{is_known_system_sender, SYSTEM_TRANSACTION_TYPE};
11+
use foundry_common::{is_known_system_sender, shell, SYSTEM_TRANSACTION_TYPE};
1212
use foundry_compilers::artifacts::EvmVersion;
1313
use foundry_config::{
1414
figment::{
@@ -48,10 +48,6 @@ pub struct RunArgs {
4848
#[arg(long)]
4949
quick: bool,
5050

51-
/// Prints the full address of the contract.
52-
#[arg(long, short)]
53-
verbose: bool,
54-
5551
/// Label addresses in the trace.
5652
///
5753
/// Example: 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045:vitalik.eth
@@ -252,7 +248,7 @@ impl RunArgs {
252248
self.label,
253249
self.debug,
254250
self.decode_internal,
255-
self.verbose,
251+
shell::verbosity() > 0,
256252
)
257253
.await?;
258254

crates/cast/bin/cmd/wallet/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ pub enum WalletSubcommands {
183183
#[arg(value_name = "MNEMONIC_INDEX_OR_DERIVATION_PATH")]
184184
mnemonic_index_or_derivation_path_override: Option<String>,
185185

186-
/// Verbose mode, print the address and private key.
187-
#[arg(short = 'v', long)]
188-
verbose: bool,
189-
190186
#[command(flatten)]
191187
wallet: WalletOpts,
192188
},
@@ -462,7 +458,6 @@ flag to set your key via:
462458
wallet,
463459
mnemonic_override,
464460
mnemonic_index_or_derivation_path_override,
465-
verbose,
466461
} => {
467462
let (index_override, derivation_path_override) =
468463
match mnemonic_index_or_derivation_path_override {
@@ -485,7 +480,7 @@ flag to set your key via:
485480
.await?;
486481
match wallet {
487482
WalletSigner::Local(wallet) => {
488-
if verbose {
483+
if shell::verbosity() > 0 {
489484
sh_println!("Address: {}", wallet.address())?;
490485
sh_println!(
491486
"Private key: 0x{}",

crates/cast/tests/cli/main.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Options:
3333
3434
Display options:
3535
--color <COLOR>
36-
Log messages coloring
36+
The color of the log messages
3737
3838
Possible values:
3939
- auto: Intelligently guess whether to use color output (default)
@@ -46,8 +46,18 @@ Display options:
4646
-q, --quiet
4747
Do not print log messages
4848
49-
--verbose
50-
Use verbose output
49+
-v, --verbosity...
50+
Verbosity level of the log messages.
51+
52+
Pass multiple times to increase the verbosity (e.g. -v, -vv, -vvv).
53+
54+
Depending on the context the verbosity levels have different meanings.
55+
56+
For example, the verbosity levels of the EVM are:
57+
- 2 (-vv): Print logs for all tests.
58+
- 3 (-vvv): Print execution traces for failing tests.
59+
- 4 (-vvvv): Print execution traces for all tests, and setup traces for failing tests.
60+
- 5 (-vvvvv): Print execution and setup traces for all tests.
5161
5262
Find more information in the book: http://book.getfoundry.sh/reference/cast/cast.html
5363

crates/cli/src/opts/shell.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
use clap::Parser;
2-
use foundry_common::shell::{ColorChoice, OutputFormat, Shell, Verbosity};
1+
use clap::{ArgAction, Parser};
2+
use foundry_common::shell::{ColorChoice, OutputFormat, OutputMode, Shell, Verbosity};
33

44
// note: `verbose` and `quiet` cannot have `short` because of conflicts with multiple commands.
55

66
/// Global shell options.
7-
#[derive(Clone, Copy, Debug, Parser)]
7+
#[derive(Clone, Copy, Debug, Default, Parser)]
88
pub struct ShellOpts {
9-
/// Use verbose output.
10-
#[clap(long, global = true, conflicts_with = "quiet", help_heading = "Display options")]
11-
pub verbose: bool,
9+
/// Verbosity level of the log messages.
10+
///
11+
/// Pass multiple times to increase the verbosity (e.g. -v, -vv, -vvv).
12+
///
13+
/// Depending on the context the verbosity levels have different meanings.
14+
///
15+
/// For example, the verbosity levels of the EVM are:
16+
/// - 2 (-vv): Print logs for all tests.
17+
/// - 3 (-vvv): Print execution traces for failing tests.
18+
/// - 4 (-vvvv): Print execution traces for all tests, and setup traces for failing tests.
19+
/// - 5 (-vvvvv): Print execution and setup traces for all tests.
20+
#[clap(short, long, global = true, verbatim_doc_comment, conflicts_with = "quiet", action = ArgAction::Count, help_heading = "Display options")]
21+
pub verbosity: Verbosity,
1222

1323
/// Do not print log messages.
14-
#[clap(
15-
short,
16-
long,
17-
global = true,
18-
alias = "silent",
19-
conflicts_with = "verbose",
20-
help_heading = "Display options"
21-
)]
24+
#[clap(short, long, global = true, alias = "silent", help_heading = "Display options")]
2225
pub quiet: bool,
2326

2427
/// Format log messages as JSON.
@@ -31,25 +34,23 @@ pub struct ShellOpts {
3134
)]
3235
pub json: bool,
3336

34-
/// Log messages coloring.
37+
/// The color of the log messages.
3538
#[clap(long, global = true, value_enum, help_heading = "Display options")]
3639
pub color: Option<ColorChoice>,
3740
}
3841

3942
impl ShellOpts {
4043
pub fn shell(self) -> Shell {
41-
let verbosity = match (self.verbose, self.quiet) {
42-
(true, false) => Verbosity::Verbose,
43-
(false, true) => Verbosity::Quiet,
44-
(false, false) => Verbosity::Normal,
45-
(true, true) => unreachable!(),
44+
let mode = match self.quiet {
45+
true => OutputMode::Quiet,
46+
false => OutputMode::Normal,
4647
};
4748
let color = self.json.then_some(ColorChoice::Never).or(self.color).unwrap_or_default();
4849
let format = match self.json {
4950
true => OutputFormat::Json,
5051
false => OutputFormat::Text,
5152
};
5253

53-
Shell::new_with(format, color, verbosity)
54+
Shell::new_with(format, mode, color, self.verbosity)
5455
}
5556
}

crates/common/src/evm.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! CLI arguments for configuring the EVM settings.
22
33
use alloy_primitives::{map::HashMap, Address, B256, U256};
4-
use clap::{ArgAction, Parser};
4+
use clap::Parser;
55
use eyre::ContextCompat;
66
use foundry_config::{
77
figment::{
@@ -14,6 +14,8 @@ use foundry_config::{
1414
};
1515
use serde::Serialize;
1616

17+
use crate::shell;
18+
1719
/// Map keyed by breakpoints char to their location (contract address, pc)
1820
pub type Breakpoints = HashMap<char, (Address, usize)>;
1921

@@ -101,19 +103,6 @@ pub struct EvmArgs {
101103
#[serde(skip)]
102104
pub always_use_create_2_factory: bool,
103105

104-
/// Verbosity of the EVM.
105-
///
106-
/// Pass multiple times to increase the verbosity (e.g. -v, -vv, -vvv).
107-
///
108-
/// Verbosity levels:
109-
/// - 2: Print logs for all tests
110-
/// - 3: Print execution traces for failing tests
111-
/// - 4: Print execution traces for all tests, and setup traces for failing tests
112-
/// - 5: Print execution and setup traces for all tests
113-
#[arg(long, short, verbatim_doc_comment, action = ArgAction::Count)]
114-
#[serde(skip)]
115-
pub verbosity: u8,
116-
117106
/// Sets the number of assumed available compute units per second for this provider
118107
///
119108
/// default value: 330
@@ -163,9 +152,9 @@ impl Provider for EvmArgs {
163152
let error = InvalidType(value.to_actual(), "map".into());
164153
let mut dict = value.into_dict().ok_or(error)?;
165154

166-
if self.verbosity > 0 {
155+
if shell::verbosity() > 0 {
167156
// need to merge that manually otherwise `from_occurrences` does not work
168-
dict.insert("verbosity".to_string(), self.verbosity.into());
157+
dict.insert("verbosity".to_string(), shell::verbosity().into());
169158
}
170159

171160
if self.ffi {

0 commit comments

Comments
 (0)