Open peterbourgon opened 5 years ago
For me help this code
usage := ""
usageBuffer := bytes.Buffer{}
app := kingpin.New("test", "")
app.Terminate(func(int) {
usage = usageBuffer.String()
usageBuffer.Reset()
})
app.UsageWriter(&usageBuffer)
...
fmt.Println(usage)
I am trying to write some unit tests for my kingpin.Application, to test things like help output. To do that, I build the application the same as I would in my real program, and redirect output to a buffer. I also apparently have to tell the app not to terminate the program (the test) whenever it encounters an error. But when I do all of these things, I notice that the Terminate callback is called multiple times (though only when I have a subcommand) and the expected output is duplicated.
Here is a small reproducible test case.
Expected output:
Actual output:
If there is a better way to do what I want to do, I'm all ears. But for now, this looks like a bug.