Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add foundry_common::shell to unify log behavior #9109

Merged
merged 46 commits into from
Oct 23, 2024

Conversation

zerosnacks
Copy link
Member

@zerosnacks zerosnacks commented Oct 14, 2024

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!). If an error occurs upon rendering it is fowarded.
  • 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:

  • 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

Visual changes:

Old:

Screenshot from 2024-10-21 12-10-56

New:

Screenshot from 2024-10-21 12-09-44

This first PR is the set of minimal changes, a follow up will be done to add it everywhere and to also solve the issues explicitly in #8794

@zerosnacks zerosnacks self-assigned this Oct 14, 2024
@mattsse
Copy link
Member

mattsse commented Oct 14, 2024

if possible, we can do this in smaller chunks because this pr is a conflict magnet

@zerosnacks zerosnacks changed the title draft: common shell feat: add foundry_common::shell to unify log behavior Oct 15, 2024
@zerosnacks
Copy link
Member Author

zerosnacks commented Oct 15, 2024

if possible, we can do this in smaller chunks because this pr is a conflict magnet

Noted, I've tried to keep the changes to a minimum but due to the nature of the PR there are a lot of small changes across many files. I've not replaced any println!'s that are not strictly necessary (in regards to their expected behaviour w/ the --quiet flag). One thing that is possibly not strictly necessary but I feel makes a lot of sense to add is the global --json flag as there is a lot of conditional logic dependent on it. Removed the global --json flag for now.

@zerosnacks zerosnacks requested a review from DaniPopes October 17, 2024 10:09
@zerosnacks
Copy link
Member Author

zerosnacks commented Oct 17, 2024

Applied fixes from review cc @DaniPopes, would you mind checking one more time?

To avoid visual regression, applied a change to style warning message content in yellow and error message content in red.

@zerosnacks
Copy link
Member Author

zerosnacks commented Oct 17, 2024

Applied a minor fix for conditional rendering of failed tests when --junit flag is passed to avoid modifying the global shell behavior

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid visual regression, applied a change to style warning message content in yellow and error message content in red.

This is not right, only the "warn"/"error" should be styled

crates/common/src/io/macros.rs Outdated Show resolved Hide resolved
@zerosnacks
Copy link
Member Author

zerosnacks commented Oct 21, 2024

To avoid visual regression, applied a change to style warning message content in yellow and error message content in red.

This is not right, only the "warn"/"error" should be styled

Reverted the style change as result of internal poll, now renders as follows again:

Screenshot from 2024-10-21 12-09-44

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high level review, lgtm

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@zerosnacks zerosnacks merged commit cd71da4 into master Oct 23, 2024
22 checks passed
@zerosnacks zerosnacks deleted the zerosnacks/common-shell-2 branch October 23, 2024 12:14
leovct pushed a commit to leovct/foundry that referenced this pull request Oct 23, 2024
)

* replace existing shell::println, add macros

* finish replacing shell::println

* remove p_println

* remove redundant quiet or silent variables

* install global shells in binaries

* CastArgs -> Cast, Cast -> CastInstance

* fix tests, always initialize Mutex::new(Shell::new()) on initial access, for some reason cfg!(test) path is not handled when running with tokio tests

* revert .quiet(true)

* add back quiet

* undo CastInstance -> Cast, Cast -> CastArgs

* add global --json format

* use global --json flag

* revert sequence / multisequence save silent mode

* fix failing tests

* fix tests

* fix tests

* replace cli_warn with sh_warn

* use shell json directly instead of passing in

* clean up, document print modes in respect to --quiet flag

* group shell options under display options

* revert global --json flag

* remove redundant import

* fix: quiet

* remove faulty argument conflict test as there is no way to currently assert a conflict between global and local args without custom reject at runtime

* add back conflicts_with quiet flag, global args w/ conflicts_with works fine

* remove yellow()

* Apply suggestions from code review

- update dependencies
- use default

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* fix deprecated terminal_size method

* revert quiet flag, fix os:fd import for windows

* add replacing tests, add back quiet conflicting flag

* make output windows compatible

* to avoid visual regression, style warning message content in yellow, error message content in red - both not bold

* fix docs links

* fix junit throwing mixed content on warnings, avoid modifying global verbosity

* remove set_verbosity shell helper, redundant

* revert default .expect on printing, prefer passing. revert message style formatting - no longer style the message

* fix doc test, fix formatting

* fix merge issues

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
rplusq pushed a commit to rplusq/foundry that referenced this pull request Nov 29, 2024
)

* replace existing shell::println, add macros

* finish replacing shell::println

* remove p_println

* remove redundant quiet or silent variables

* install global shells in binaries

* CastArgs -> Cast, Cast -> CastInstance

* fix tests, always initialize Mutex::new(Shell::new()) on initial access, for some reason cfg!(test) path is not handled when running with tokio tests

* revert .quiet(true)

* add back quiet

* undo CastInstance -> Cast, Cast -> CastArgs

* add global --json format

* use global --json flag

* revert sequence / multisequence save silent mode

* fix failing tests

* fix tests

* fix tests

* replace cli_warn with sh_warn

* use shell json directly instead of passing in

* clean up, document print modes in respect to --quiet flag

* group shell options under display options

* revert global --json flag

* remove redundant import

* fix: quiet

* remove faulty argument conflict test as there is no way to currently assert a conflict between global and local args without custom reject at runtime

* add back conflicts_with quiet flag, global args w/ conflicts_with works fine

* remove yellow()

* Apply suggestions from code review

- update dependencies
- use default

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* fix deprecated terminal_size method

* revert quiet flag, fix os:fd import for windows

* add replacing tests, add back quiet conflicting flag

* make output windows compatible

* to avoid visual regression, style warning message content in yellow, error message content in red - both not bold

* fix docs links

* fix junit throwing mixed content on warnings, avoid modifying global verbosity

* remove set_verbosity shell helper, redundant

* revert default .expect on printing, prefer passing. revert message style formatting - no longer style the message

* fix doc test, fix formatting

* fix merge issues

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

4 participants