-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
command: discard output from flags package and return errs directly #22373
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question but non-blocking
@@ -353,26 +351,7 @@ func (m *Meta) contextOpts() *terraform.ContextOpts { | |||
// defaultFlagSet creates a default flag set for commands. | |||
func (m *Meta) defaultFlagSet(n string) *flag.FlagSet { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 deletion of code that says This is kind of a hack
@@ -36,7 +36,8 @@ func (c *StateMvCommand) Run(args []string) int { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do wonder what RunResultHelp was (and if it is useful, or if it remains useful?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.