foundry
foundry copied to clipboard
feat: add `foundry_common::shell` to unify log behavior
Motivation
To unify the shell implementation for improved consistency.
Solution
- Implements a common global shell for all output, correctly rendering to
stdout
on logs (sh_println!
) andstderr
on warnings and errors (sh_eprintln!
,sh_warn!
,sh_err!
). - Adds a global
--quiet
/-q
flag, easily checked against withshell::is_quiet()
for conditional logic - Aims to keep the diff as low as possible whilst addressing the removal of existing methods like
p_println
,cli_warn
,shell::println
etc..
Changes from initial common shell implementation:
- Macros now implement an
unwrap
directly on them, avoiding the need to pass / introduce?
anywhere. -
sh_println!
/sh_eprintln!
/sh_warn!
now all listen to the--quiet
flag - Regular output logs are rendered with
sh_println!
as opposed tosh_eprintln!
- Warnings are rendered to
stderr
output
To check / fix from https://github.com/foundry-rs/foundry/pull/6569:
- [ ] Evaluate https://github.com/foundry-rs/foundry/issues/3981.
- [ ] Evaluate https://github.com/foundry-rs/foundry/issues/2433.
- [ ] Evaluate https://github.com/foundry-rs/foundry/issues/1976.
- [ ] Evaluate https://github.com/foundry-rs/foundry/issues/7055.
- [ ] Evaluate https://github.com/foundry-rs/foundry/issues/8568
Follow ups:
- [ ] Introduce a global
--json
flag, similar to the global--quiet
flag. - [ ] With
shell::Format::Json
enabled set the verbosity toquiet
, disabling all output except for errors. - [ ] Introduce a
sh_json!
macro that renders JSON to the console ifshell::Format::Json
is active, either pretty or not. This could be automatically a no-op in anything except when the--json
flag is passed. - [ ] Make sure all commands and modes are
--json
compatible, related: https://github.com/foundry-rs/foundry/issues/8794. With the current proposed change Anvil for example now has a--json
flag but is not yet compatible. What--json
means in context dependent to the command / tool. Goal is that it becomes much easier to chain Foundry into other tools. - [ ] Re-add additional macros like
note
andstatus
and implement - [ ] Enable Clippy lint, search and replace.