Skip to content
Myr

doc: hide hidden parent flags (#686)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fixes #685

authored by James DeFelice · committed by Eric Paris · parent 7ee208b · Browse files · 6 files+89 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+89 added−6 removed

  • other:+89 added−6 removed

6 files+89 added−6 removed

modified:doc/man_docs_test.go+36 added
45 unmodified lines
46 checkStringOmits(t, output, translate(deprecatedCmd.Name()))47 checkStringContains(t, output, translate("Auto generated"))48}4950func TestGenManNoHiddenParents(t *testing.T) {51 header := &GenManHeader{52 Title: "Project",53 Section: "2",54 }5556 // We generate on a subcommand so we have both subcommands and parents57 for _, name := range []string{"rootflag", "strtwo"} {58 f := rootCmd.PersistentFlags().Lookup(name)59 f.Hidden = true60 defer func() { f.Hidden = false }()61 }62 buf := new(bytes.Buffer)63 if err := GenMan(echoCmd, header, buf); err != nil {64 t.Fatal(err)65 }66 output := buf.String()6768 // Make sure parent has - in CommandPath() in SEE ALSO:69 parentPath := echoCmd.Parent().CommandPath()70 dashParentPath := strings.Replace(parentPath, " ", "-", -1)71 expected := translate(dashParentPath)72 expected = expected + "(" + header.Section + ")"73 checkStringContains(t, output, expected)7475 checkStringContains(t, output, translate(echoCmd.Name()))76 checkStringContains(t, output, translate(echoCmd.Name()))77 checkStringContains(t, output, "boolone")78 checkStringOmits(t, output, "rootflag")79 checkStringContains(t, output, translate(rootCmd.Name()))80 checkStringContains(t, output, translate(echoSubCmd.Name()))81 checkStringOmits(t, output, translate(deprecatedCmd.Name()))82 checkStringContains(t, output, translate("Auto generated"))83 checkStringOmits(t, output, "OPTIONS INHERITED FROM PARENT COMMANDS")84}8586func TestGenManNoGenTag(t *testing.T) {87 echoCmd.DisableAutoGenTag = true88 defer func() { echoCmd.DisableAutoGenTag = false }()89
124 unmodified lines
modified:doc/man_docs.go+2 added-2 removed
174 unmodified lines
175}176177func manPrintOptions(buf *bytes.Buffer, command *cobra.Command) {178 flags := command.NonInheritedFlags()179 if flags.HasFlags() {179 if flags.HasAvailableFlags() {180 buf.WriteString("# OPTIONS\n")181 manPrintFlags(buf, flags)182 buf.WriteString("\n")183 }184 flags = command.InheritedFlags()185 if flags.HasFlags() {185 if flags.HasAvailableFlags() {186 buf.WriteString("# OPTIONS INHERITED FROM PARENT COMMANDS\n")187 manPrintFlags(buf, flags)188 buf.WriteString("\n")189 }
47 unmodified lines
modified:doc/md_docs_test.go+24 added
23 unmodified lines
24 checkStringContains(t, output, "rootflag")25 checkStringContains(t, output, rootCmd.Short)26 checkStringContains(t, output, echoSubCmd.Short)27 checkStringOmits(t, output, deprecatedCmd.Short)28 checkStringContains(t, output, "Options inherited from parent commands")29}3031func TestGenMdNoHiddenParents(t *testing.T) {32 // We generate on subcommand so we have both subcommands and parents.33 for _, name := range []string{"rootflag", "strtwo"} {34 f := rootCmd.PersistentFlags().Lookup(name)35 f.Hidden = true36 defer func() { f.Hidden = false }()37 }38 buf := new(bytes.Buffer)39 if err := GenMarkdown(echoCmd, buf); err != nil {40 t.Fatal(err)41 }42 output := buf.String()4344 checkStringContains(t, output, echoCmd.Long)45 checkStringContains(t, output, echoCmd.Example)46 checkStringContains(t, output, "boolone")47 checkStringOmits(t, output, "rootflag")48 checkStringContains(t, output, rootCmd.Short)49 checkStringContains(t, output, echoSubCmd.Short)50 checkStringOmits(t, output, deprecatedCmd.Short)51 checkStringOmits(t, output, "Options inherited from parent commands")52}5354func TestGenMdNoTag(t *testing.T) {55 rootCmd.DisableAutoGenTag = true56 defer func() { rootCmd.DisableAutoGenTag = false }()57
41 unmodified lines
modified:doc/md_docs.go+2 added-2 removed
27 unmodified lines
2829func printOptions(buf *bytes.Buffer, cmd *cobra.Command, name string) error {30 flags := cmd.NonInheritedFlags()31 flags.SetOutput(buf)32 if flags.HasFlags() {32 if flags.HasAvailableFlags() {33 buf.WriteString("### Options\n\n```\n")34 flags.PrintDefaults()35 buf.WriteString("```\n\n")36 }3738 parentFlags := cmd.InheritedFlags()39 parentFlags.SetOutput(buf)40 if parentFlags.HasFlags() {40 if parentFlags.HasAvailableFlags() {41 buf.WriteString("### Options inherited from parent commands\n\n```\n")42 parentFlags.PrintDefaults()43 buf.WriteString("```\n\n")44 }
115 unmodified lines
modified:doc/rest_docs_test.go+23 added
25 unmodified lines
26 checkStringContains(t, output, echoSubCmd.Short)27 checkStringOmits(t, output, deprecatedCmd.Short)28}2930func TestGenRSTNoHiddenParents(t *testing.T) {31 // We generate on a subcommand so we have both subcommands and parents32 for _, name := range []string{"rootflag", "strtwo"} {33 f := rootCmd.PersistentFlags().Lookup(name)34 f.Hidden = true35 defer func() { f.Hidden = false }()36 }37 buf := new(bytes.Buffer)38 if err := GenReST(echoCmd, buf); err != nil {39 t.Fatal(err)40 }41 output := buf.String()4243 checkStringContains(t, output, echoCmd.Long)44 checkStringContains(t, output, echoCmd.Example)45 checkStringContains(t, output, "boolone")46 checkStringOmits(t, output, "rootflag")47 checkStringContains(t, output, rootCmd.Short)48 checkStringContains(t, output, echoSubCmd.Short)49 checkStringOmits(t, output, deprecatedCmd.Short)50 checkStringOmits(t, output, "Options inherited from parent commands")51}5253func TestGenRSTNoTag(t *testing.T) {54 rootCmd.DisableAutoGenTag = true55 defer func() { rootCmd.DisableAutoGenTag = false }()56
43 unmodified lines
modified:doc/rest_docs.go+2 added-2 removed
27 unmodified lines
2829func printOptionsReST(buf *bytes.Buffer, cmd *cobra.Command, name string) error {30 flags := cmd.NonInheritedFlags()31 flags.SetOutput(buf)32 if flags.HasFlags() {32 if flags.HasAvailableFlags() {33 buf.WriteString("Options\n")34 buf.WriteString("~~~~~~~\n\n::\n\n")35 flags.PrintDefaults()36 buf.WriteString("\n")37 }3839 parentFlags := cmd.InheritedFlags()40 parentFlags.SetOutput(buf)41 if parentFlags.HasFlags() {41 if parentFlags.HasAvailableFlags() {42 buf.WriteString("Options inherited from parent commands\n")43 buf.WriteString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n::\n\n")44 parentFlags.PrintDefaults()45 buf.WriteString("\n")
140 unmodified lines