-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix documentation inconsistencies #2043
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -31,15 +31,15 @@ func printOptions(buf *bytes.Buffer, cmd *cobra.Command, name string) error { | |||||||||||||||||||||||||||||||
flags := cmd.NonInheritedFlags() | ||||||||||||||||||||||||||||||||
flags.SetOutput(buf) | ||||||||||||||||||||||||||||||||
if flags.HasAvailableFlags() { | ||||||||||||||||||||||||||||||||
buf.WriteString("### Options\n\n```\n") | ||||||||||||||||||||||||||||||||
buf.WriteString("### Flags\n\n```\n") | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing Line 43 in 8b1eba4
so this makes me abit hesitant since that struct is a public API and I would rather not change that too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I see there are more inconsistencies there, but I think it would be best to handle those in another branch. Especially when there's a function that may need to change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also discovered that the inconsistencies are present in the man tree generation as well: Lines 187 to 200 in a0a6ae0
|
||||||||||||||||||||||||||||||||
flags.PrintDefaults() | ||||||||||||||||||||||||||||||||
buf.WriteString("```\n\n") | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
parentFlags := cmd.InheritedFlags() | ||||||||||||||||||||||||||||||||
parentFlags.SetOutput(buf) | ||||||||||||||||||||||||||||||||
if parentFlags.HasAvailableFlags() { | ||||||||||||||||||||||||||||||||
buf.WriteString("### Options inherited from parent commands\n\n```\n") | ||||||||||||||||||||||||||||||||
buf.WriteString("### Flags inherited from parent commands\n\n```\n") | ||||||||||||||||||||||||||||||||
parentFlags.PrintDefaults() | ||||||||||||||||||||||||||||||||
buf.WriteString("```\n\n") | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
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'm not a fan of this change: while you're technically correct (what we're calling global flags are just flags inherited from the top level command), in spirit, they are global flags.
This would be a pretty confusing change for people who've used cobra for years.
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.
They are not necessarily inherited from top level command, just a parent command, which makes the "Global Flags" statement even more confusing when having multiple levels of sub commands.
I would argue that it's more confusing calling them something they really are not, i.e. "Global Flags", then calling them what they actually are, technically and factually. Whether they may be global "in spirit" or not, I think actual usage is more important, and, at least from our point of view, they are not treated as global for sure.
I guess a compromise would be something like "Global flags inherited from parent command" or something like that.
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.
Hmmm that's a very fair point: this is probably one of those legacy inconsistencies that has popped up as we've expanded the command / flag system. It's not really global, like you said, since it is inherited from some parent.
Anyone else have opinions here.
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.
The point is valid but I don’t think it justifies changing a formulation that tools have been using for years.
In fact, I wonder if many tools aren’t putting the inherited flags mostly on the root command which would make them global flags so although this printout is not technically correct, it is in practice the right thing, and what existing tools are expecting
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.
It's fair to say that this change would be somewhat of an inconvenience for developers using the tool and the cost may be a bit high for this change. I'll revert the print out because of that in this PR.
I think it's good though to consider that application developers aren't the end users for cobra. The end users are the ones actually using the application and the ones that would actually read the help documentation. In our case, the "Global Flags" print has actually caused a bit of confusion.
Anyway, dealing with this slight inconsistency between markdown and help func is the point of this PR and I'll revert it back for this. How this is worded would probably a discussion to have at some other point.