Skip to content

Instantly share code, notes, and snippets.

@markbates
Created March 4, 2022 21:41
Show Gist options
  • Save markbates/2052b33342cb94f6a6bcbfac16f5c69b to your computer and use it in GitHub Desktop.
Save markbates/2052b33342cb94f6a6bcbfac16f5c69b to your computer and use it in GitHub Desktop.
package cli
import (
"io"
"os"
)
// IO represents the standard input, output, and error stream.
type IO struct {
In io.Reader // standard input
Out io.Writer // standard output
Err io.Writer // standard error
}
// Stdout returns IO.In.
// Defaults to os.Stdout.
func (oi IO) Stdout() io.Writer {
if oi.Out == nil {
return os.Stdout
}
return oi.Out
}
// Stderr returns IO.Err.
// Defaults to os.Stderr.
func (oi IO) Stderr() io.Writer {
if oi.Err == nil {
return os.Stderr
}
return oi.Err
}
// Stdin returns IO.In.
// Defaults to os.Stdin.
func (oi IO) Stdin() io.Reader {
if oi.In == nil {
return os.Stdin
}
return oi.In
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment