command: discard output from flags package and return errs directly#22373
command: discard output from flags package and return errs directly#22373mildwonkey merged 1 commit intomasterfrom
Conversation
Any command using meta.defaultFlagSet *might* occassionally exit before the flag package's output got written. This caused flag error messages to get lost. This PR discards the flag package output in favor of directly returning the error to the end user.
pselle
left a comment
There was a problem hiding this comment.
One question but non-blocking
| f := flag.NewFlagSet(n, flag.ContinueOnError) | ||
|
|
||
| // Create an io.Writer that writes to our Ui properly for errors. | ||
| // This is kind of a hack, but it does the job. Basically: create |
There was a problem hiding this comment.
👏 deletion of code that says This is kind of a hack
| cmdFlags.StringVar(&c.statePath, "state", "", "path") | ||
| cmdFlags.StringVar(&statePathOut, "state-out", "", "path") | ||
| if err := cmdFlags.Parse(args); err != nil { | ||
| return cli.RunResultHelp |
There was a problem hiding this comment.
I do wonder what RunResultHelp was (and if it is useful, or if it remains useful?)
There was a problem hiding this comment.
Ah yeah, it took me awhile to track this down.
This is an exit code from "github.com/mitchellh/cli". When it's used as an exit code, the cli package prints the usage text before exiting. It's used in other tf commands, but in this case (because cmdFlags.Parse also prints the usage) it resulted in the help/usage text getting printed twice.
I doubly appreciate the question because when I went back to check something I found the last bit of ~magic wherein the flags package was printing the usage, thanks! 👏
There was a problem hiding this comment.
thanks for the info, and glad it helped! 🙌
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Any command using meta.defaultFlagSet might occassionally exit before
the flag package's output got written. This caused flag error messages
to get lost. This PR discards the flag package output in favor of
directly returning the error to the end user.
This PR DIRECTLY CONFLICTS with #22372
I am equally happy to choose one over the other - if we are concerned about the implications of this change, starting with a single command is not a bad option.