Standard library / flag
flag.FlagSet.SetOutput()
Changes the destination for usage and error messages; not normal program output. Expected stdout: 'true true\n'.
Formal Syntax & Structure
go syntaxgo
func (f *FlagSet) SetOutput(output io.Writer)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| output | io.Writer | Writer for usage and parsing diagnostics. |
Working Example
Example Snippetgo
package main
import ( "bytes" "flag" "fmt" "strings")
func main() { f := flag.NewFlagSet("demo", flag.ContinueOnError) var b bytes.Buffer f.SetOutput(&b) err := f.Parse([]string{"-unknown"}) fmt.Println(err != nil, strings.Contains(b.String(), "unknown"))}