foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat: add `foundry_common::shell` to unify log behavior

Open zerosnacks opened this issue 4 months ago • 5 comments

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!) and stderr on warnings and errors (sh_eprintln!, sh_warn!, sh_err!).
  • Adds a global --quiet / -q flag, easily checked against with shell::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 to sh_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 to quiet, disabling all output except for errors.
  • [ ] Introduce a sh_json! macro that renders JSON to the console if shell::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 and status and implement
  • [ ] Enable Clippy lint, search and replace.

zerosnacks avatar Oct 14 '24 13:10 zerosnacks