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

Add cargo-style output diagnostics. #859

Merged
merged 1 commit into from
Jun 27, 2022
Merged

Conversation

Alexhuszagh
Copy link
Contributor

@Alexhuszagh Alexhuszagh commented Jun 25, 2022

Adds the quiet and color command-line flags, where color supports auto, always, and never`. These command-line flags are parsed to a verbosity which can be quiet, normal, or verbose.

With these, we then have the stderr message formatters:

  • fatal_usage: print a fatal error message with the failing argument, and add a help context menu for how to use cross.
  • fatal: print red 'error' message and exit with an error code
  • error: print red 'error' message
  • warn: print amber 'warning' message
  • note: print cyan 'note' message
  • status: print an uncolored and unprefixed 'status' message

We have the stdout message formatters:

  • print: always print the message
  • info: print the message as long as the verbosity is not quiet
  • debug: only print the message if the output is not quiet

We also have a few specialized error handlers, and methods to help ensure we can have flexible error reporting in the future:

  • status_stderr
  • status_stdout

The command extensions now have, print, info, and debug, which formats the command and sends it to the shell. This allows us to avoid using print_verbose where we sometimes manually override the default setting.

A few of these settings aren't currently used (such as info and status, but they're a very common pattern), so we can ensure we have the necessary utilities to ensure we can properly format messages in the future. A few like shell::print are practically identical to println!, but this allows us to customize it if need be in the future.

Solves parts of #797.

@Alexhuszagh
Copy link
Contributor Author

Alexhuszagh commented Jun 25, 2022

We only manually intercept --color if it's invalid, or --verbose and --quiet if both are set, and let everything else be handled by cargo. Some sample differences (where target/debug/cross is my local branch, and cross is the v0.2.2 release) are:

Color
Fallback
Quiet Verbose
Warning

There's quite a dramatic difference.

For a few things, like Github Actions, to ensure we don't remove the println!/panic! statements, I've moved them all to xtask/util and labeled them as follows:

  • gha_print
  • gha_error
  • gha_output

I've also updated it so in quiet mode it silences rustup.

Cargo.toml Outdated Show resolved Hide resolved
@Alexhuszagh Alexhuszagh added this to the v0.2.3 milestone Jun 26, 2022
Copy link
Member

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

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

Awesome, looks great

I don't think this solves #797 however, but it's a good way to it

bors r+

bors bot added a commit that referenced this pull request Jun 27, 2022
859: Add cargo-style output diagnostics. r=Emilgardis a=Alexhuszagh

Adds the quiet and color command-line flags, where color supports `auto`, always`, and `never`. These command-line flags are parsed to a verbosity which can be quiet, normal, or verbose.

With these, we then have the stderr message formatters:
- `fatal_usage`: print a fatal error message with the failing argument, and add a help context menu for how to use cross.
- `fatal`: print red 'error' message and exit with an error code
- `error`: print red 'error' message
- `warn`: print amber 'warning' message
- `note`: print cyan 'note' message
- `status`: print an uncolored and unprefixed 'status' message

We have the stdout message formatters:
- `print`: always print the message
- `info`: print the message as long as the verbosity is not quiet
- `debug`: only print the message if the output is not quiet

We also have a few specialized error handlers, and methods to help ensure we can have flexible error reporting in the future:
- `status_stderr`
- `status_stdout`

The command extensions now have, `print`, `info`, and `debug`, which formats the command and sends it to the shell. This allows us to avoid using `print_verbose` where we sometimes manually override the default setting.

A few of these settings aren't currently used (such as `info` and `status`, but they're a very common pattern), so we can ensure we have the necessary utilities to ensure we can properly format messages in the future. A few like `shell::print` are practically identical to `println!`, but this allows us to customize it if need be in the future.

Solves parts of #797.

Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
CHANGELOG.md Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors bot commented Jun 27, 2022

Build failed:

Adds the quiet and color command-line flags, where color supports `auto`, always`, and `never`. These command-line flags are parsed to a verbosity which can be quiet, normal, or verbose.

With these, we then have the stderr message formatters:
- `fatal_usage`: print a fatal error message with the failing argument, and add a help context menu for how to use cross.
- `fatal`: print red 'error' message and exit with an error code
- `error`: print red 'error' message
- `warn`: print amber 'warning' message
- `note`: print cyan 'note' message
- `status`: print an uncolored and unprefixed 'status' message

We have the stdout message formatters:
- `print`: always print the message
- `info`: print the message as long as the verbosity is not quiet
- `debug`: only print the message if the output is not quiet

We also have a few specialized error handlers, and methods to help ensure we can have flexible error reporting in the future:
- `status_stderr`
- `status_stdout`

The command extensions now have, `print`, `info`, and `debug`, which formats the command and sends it to the shell. This allows us to avoid using `print_verbose` where we sometimes manually override the default setting.

Closes cross-rs#797.
Copy link
Member

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

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

bors r+

@bors
Copy link
Contributor

bors bot commented Jun 27, 2022

Build succeeded:

@bors bors bot merged commit eb2b8ad into cross-rs:main Jun 27, 2022
bors bot added a commit that referenced this pull request Jul 6, 2022
911: Structify more of the internals to simplify the implementation. r=Emilgardis a=Alexhuszagh

Reduces the number of arguments to the function signatures, making the code much easier to understand, and relocates some things. For example, `docker_in_docker` is now associated with `Engine`, and now with `cli::Args`. Likewise, unstable doctests is now a part of `Environment` and not `cli::Args`. `MessageInfo` now stores mutable state (needs to clear lines) and is no longer copyable, and a single instance is created in lib and passed around everywhere as a mutable reference.

The changes with `MessageInfo` will allow us to erase lines in the future, both from `stderr` and `stdout`, which we currently don't use but will allow us to close #859.

 This also fixes an issue where `-vv+` was not recognized as a valid verbose flag: `cargo` can handle 1 or more `v` characters. Also allowed parsing of `--color=value` args, when we previously only accepted `--color value`.

Co-authored-by: Alex Huszagh <ahuszagh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants