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(spin): Add support for --show-error for the spinner. #440

Closed

Conversation

elliotcourant
Copy link
Contributor

This makes it so that if the --show-error flag is provided then the
full output of the command will be printed if the command fails. This
kind of works in conjuncture with --show-output in that if the command
succeeds only STDOUT is pushed. If the command fails both STDOUT and
STDERR are pushed.

This builds off of #371

Resolves #55

Fixes #55

Changes

  • Adds support for a --show-error flag for the spinner command.

Examples

gum spin -s minidot --show-error -- bash -c "sleep 1 && echo 'you can see me if the command fails' && exit 1"
# you can see me if the command fails
# exit status 1
gum spin -s minidot --show-error -- bash -c "sleep 1 && echo 'you can see me if the command fails' && exit 0"
# (no output)

This makes it so that if the `--show-error` flag is provided then the
full output of the command will be printed if the command fails. This
kind of works in conjuncture with `--show-output` in that if the command
succeeds only STDOUT is pushed. If the command fails both `STDOUT` and
`STDERR` are pushed.

This builds off of charmbracelet#371

Resolves charmbracelet#55
Comment on lines +65 to +66
stdout := io.MultiWriter(&bothbuf, &errbuf)
stderr := io.MultiWriter(&bothbuf, &outbuf)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By doing this the bothbuf will have the output of both STDERR and STDOUT but it will be in the order it was written by the process.

If we have the buffers entirely separate and the writes to each were interleaved in any way, this might cause the output to be confusing or be inaccurate.

@pingiun
Copy link
Contributor

pingiun commented Mar 1, 2024

I would really like to have this feature in gum, can I help to get it merged?

@elliotcourant
Copy link
Contributor Author

elliotcourant commented Mar 27, 2024

This PR has been taken over in #518

maaslalani pushed a commit that referenced this pull request Mar 28, 2024
… (#518)

* feat(spin): Add support for `--show-error` for the spinner.

This makes it so that if the `--show-error` flag is provided then the
full output of the command will be printed if the command fails. This
kind of works in conjuncture with `--show-output` in that if the command
succeeds only STDOUT is pushed. If the command fails both `STDOUT` and
`STDERR` are pushed.

This builds off of #371

Resolves #55

* chore: Fix formatting

---------

Co-authored-by: Elliot Courant <me@elliotcourant.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] add option for gum spin to dump output on error
2 participants