Created
March 4, 2022 21:41
-
-
Save markbates/2052b33342cb94f6a6bcbfac16f5c69b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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