Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix documentation inconsistencies #2043

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/md_docs.go
Expand Up @@ -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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing Options to Flags in the markdown docs seems fine. Although this introduces another inconsistency between what we internally call "options" in the docs generation. I.e., look at what we do for yaml docs:

InheritedOptions []cmdOption `yaml:"inherited_options,omitempty"`

so this makes me abit hesitant since that struct is a public API and I would rather not change that too

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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:

cobra/doc/man_docs.go

Lines 187 to 200 in a0a6ae0

func manPrintOptions(buf io.StringWriter, command *cobra.Command) {
flags := command.NonInheritedFlags()
if flags.HasAvailableFlags() {
cobra.WriteStringAndCheck(buf, "# OPTIONS\n")
manPrintFlags(buf, flags)
cobra.WriteStringAndCheck(buf, "\n")
}
flags = command.InheritedFlags()
if flags.HasAvailableFlags() {
cobra.WriteStringAndCheck(buf, "# OPTIONS INHERITED FROM PARENT COMMANDS\n")
manPrintFlags(buf, flags)
cobra.WriteStringAndCheck(buf, "\n")
}
}

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("### Global Flags\n\n```\n")
parentFlags.PrintDefaults()
buf.WriteString("```\n\n")
}
Expand Down
6 changes: 3 additions & 3 deletions doc/md_docs_test.go
Expand Up @@ -39,7 +39,7 @@ func TestGenMdDoc(t *testing.T) {
checkStringContains(t, output, rootCmd.Short)
checkStringContains(t, output, echoSubCmd.Short)
checkStringOmits(t, output, deprecatedCmd.Short)
checkStringContains(t, output, "Options inherited from parent commands")
checkStringContains(t, output, "Global Flags")
}

func TestGenMdDocWithNoLongOrSynopsis(t *testing.T) {
Expand All @@ -52,7 +52,7 @@ func TestGenMdDocWithNoLongOrSynopsis(t *testing.T) {

checkStringContains(t, output, dummyCmd.Example)
checkStringContains(t, output, dummyCmd.Short)
checkStringContains(t, output, "Options inherited from parent commands")
checkStringContains(t, output, "Global Flags")
checkStringOmits(t, output, "### Synopsis")
}

Expand All @@ -76,7 +76,7 @@ func TestGenMdNoHiddenParents(t *testing.T) {
checkStringContains(t, output, rootCmd.Short)
checkStringContains(t, output, echoSubCmd.Short)
checkStringOmits(t, output, deprecatedCmd.Short)
checkStringOmits(t, output, "Options inherited from parent commands")
checkStringOmits(t, output, "Global Flags")
}

func TestGenMdNoTag(t *testing.T) {
Expand Down