In the *Commander.Execute method, a new flag.FlagSet is initialized for the command to run. However, the FlagSet.output of that FlagSet is not initialized, which causes potential errors to be reported by f.failf(), which in turn invokes f.Output(), which falls back to os.Stderr because the field is not initialized.
This causes the error output not to match the commander .Error property, preventing capture/redirection especially during tests.
What should happen
The output of the newly created FieldSet should be set to either the cdr.topFlags output, or to cdr.Error during initialization, with the latter slightly being more logical.
Description
In the
*Commander.Execute
method, a newflag.FlagSet
is initialized for the command to run. However, theFlagSet.output
of thatFlagSet
is not initialized, which causes potential errors to be reported byf.failf()
, which in turn invokesf.Output()
, which falls back toos.Stderr
because the field is not initialized.This causes the error output not to match the commander
.Error
property, preventing capture/redirection especially during tests.What should happen
The output of the newly created
FieldSet
should be set to either thecdr.topFlags
output, or tocdr.Error
during initialization, with the latter slightly being more logical.