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

Support simple output format #370

Closed
spenserblack opened this issue May 25, 2022 · 6 comments · Fixed by #431
Closed

Support simple output format #370

spenserblack opened this issue May 25, 2022 · 6 comments · Fixed by #431

Comments

@spenserblack
Copy link

First, thank you for making this crate!

I made a simple GitHub Action so that I could use this during workflows. One of the things I've noticed is that there doesn't seem to be simple output, but either a "pretty" output for humans, or multiple JSON outputs.

For the purposes of writing shell scripts to check the MSRV, I think it would be even beneficial to have an output format that does nothing but:

  • Prints the version and exits 0
  • Prints an error like "could not find version" to STDERR and exits 1

This would remove the need for a tool like jq to parse the output, and shell scripts that use cargo msrv could be simplified to something vaguely like

# obviously something more useful would happen than just cat to STDOUT :)
cargo msrv > version 2> error || cat error && cat version
@foresterre
Copy link
Owner

Sounds plausible! I'll see what I can do :)

@foresterre foresterre modified the milestones: v0.17.0, v0.16.0 May 25, 2022
@foresterre
Copy link
Owner

I'm currently working on implementing a new way to report output to the user. I hope to complete that process this or next week. After that process is complete, I'll add this, and then we're about ready for a new release as well.

@foresterre
Copy link
Owner

foresterre commented Aug 2, 2022

Hey @spenserblack, I have been working on this feature request. Currently, I'm printing all output to stderr*, but looking at your example of a shell script, I think it would be favourable for your use case to print a success to stdout and a failure to stderr. What do you think?

* Or to any W: Write, but it's limited to a single writable sink
** Using W: Write (or SW: Write, FW: Write) is favourable over Stdio and Stderr mostly for unit testing, where I can instead output to a byte buffer directly

@spenserblack
Copy link
Author

I think it would be favourable for your use case to print a success to stdout and a failure to stderr.

Yes, that's exactly what I was thinking 😃
Besides my use case specifically, I think for scripting in general it's useful for expected outputs to go to stdout and unexpected (failures) to go to stderr. The only common exceptions I can think of right now are

  • CLI help messages are often printed to stderr, even though cli-tool --help would be the correct usage
  • When the tool is intended to have a machine-readable output, human-readable logs might all go to stderr, even success logs

@bors bors bot closed this as completed in 4b2e329 Aug 2, 2022
@foresterre
Copy link
Owner

In #431 (merged), I added the minimal output mode, accessible via cargo msrv --output-format minimal.

Running your example script gives:

A successful run:

$ cargo msrv --output-format minimal > version 2> error || cat error && cat version
1.56.1

A failed run (i.e. no compatible version found):

$ cargo msrv --output-format minimal > version 2> error || cat error && cat version
none

Additional documentation can be found in the book here.

If you find a bug, or like to have this implementation changed (e.g. have more details about what went wrong, I would be happy to implement this as well).

@spenserblack
Copy link
Author

This is awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants