Skip to content

Commit

Permalink
Add option to show output on error
Browse files Browse the repository at this point in the history
  • Loading branch information
jelle-bigbridge committed Jun 8, 2023
1 parent 0010018 commit 868d06c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions spin/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func (o Options) Run() error {
return fmt.Errorf("failed to run spin: %w", err)
}

if o.OutputOnError && m.status != 0 {
fmt.Fprint(os.Stdout, m.stdout)
fmt.Fprint(os.Stderr, m.stderr)
}

if o.ShowOutput {
fmt.Fprint(os.Stdout, m.stdout)
fmt.Fprint(os.Stderr, m.stderr)
Expand Down
13 changes: 7 additions & 6 deletions spin/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import "github.com/charmbracelet/gum/style"
type Options struct {
Command []string `arg:"" help:"Command to run"`

ShowOutput bool `help:"Show output of command" default:"false" env:"GUM_SPIN_SHOW_OUTPUT"`
Spinner string `help:"Spinner type" short:"s" type:"spinner" enum:"line,dot,minidot,jump,pulse,points,globe,moon,monkey,meter,hamburger" default:"dot" env:"GUM_SPIN_SPINNER"`
SpinnerStyle style.Styles `embed:"" prefix:"spinner." set:"defaultForeground=212" envprefix:"GUM_SPIN_SPINNER_"`
Title string `help:"Text to display to user while spinning" default:"Loading..." env:"GUM_SPIN_TITLE"`
TitleStyle style.Styles `embed:"" prefix:"title." envprefix:"GUM_SPIN_TITLE_"`
Align string `help:"Alignment of spinner with regard to the title" short:"a" type:"align" enum:"left,right" default:"left" env:"GUM_SPIN_ALIGN"`
ShowOutput bool `help:"Show output of command" default:"false" env:"GUM_SPIN_SHOW_OUTPUT"`
OutputOnError bool `help:"Show output of command if it fails" default:"false" env:"GUM_SPIN_OUTPUT_ON_ERROR"`
Spinner string `help:"Spinner type" short:"s" type:"spinner" enum:"line,dot,minidot,jump,pulse,points,globe,moon,monkey,meter,hamburger" default:"dot" env:"GUM_SPIN_SPINNER"`
SpinnerStyle style.Styles `embed:"" prefix:"spinner." set:"defaultForeground=212" envprefix:"GUM_SPIN_SPINNER_"`
Title string `help:"Text to display to user while spinning" default:"Loading..." env:"GUM_SPIN_TITLE"`
TitleStyle style.Styles `embed:"" prefix:"title." envprefix:"GUM_SPIN_TITLE_"`
Align string `help:"Alignment of spinner with regard to the title" short:"a" type:"align" enum:"left,right" default:"left" env:"GUM_SPIN_ALIGN"`
}

0 comments on commit 868d06c

Please sign in to comment.