mirror of https://github.com/spf13/cobra.git
Check for disable auto gen tag on parents commands before filling man headers
This commit is contained in:
parent
893ebf6e36
commit
0bf8e9a869
|
@ -105,6 +105,14 @@ func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {
|
||||||
if header == nil {
|
if header == nil {
|
||||||
header = &GenManHeader{}
|
header = &GenManHeader{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cmd.HasParent() {
|
||||||
|
cmd.VisitParents(func(c *cobra.Command) {
|
||||||
|
if c.DisableAutoGenTag {
|
||||||
|
cmd.DisableAutoGenTag = c.DisableAutoGenTag
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
if err := fillHeader(header, cmd.CommandPath(), cmd.DisableAutoGenTag); err != nil {
|
if err := fillHeader(header, cmd.CommandPath(), cmd.DisableAutoGenTag); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,6 +111,32 @@ func TestGenManNoGenTag(t *testing.T) {
|
||||||
checkStringOmits(t, output, unexpected)
|
checkStringOmits(t, output, unexpected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGenManNoGenTagWithDisabledParent(t *testing.T) {
|
||||||
|
// We set the flag on a parent to check it is used in its descendance
|
||||||
|
rootCmd.DisableAutoGenTag = true
|
||||||
|
defer func() {
|
||||||
|
echoCmd.DisableAutoGenTag = false
|
||||||
|
rootCmd.DisableAutoGenTag = false
|
||||||
|
}()
|
||||||
|
|
||||||
|
header := &GenManHeader{
|
||||||
|
Title: "Project",
|
||||||
|
Section: "2",
|
||||||
|
}
|
||||||
|
|
||||||
|
// We generate on a subcommand so we have both subcommands and parents
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
if err := GenMan(echoCmd, header, buf); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
output := buf.String()
|
||||||
|
|
||||||
|
unexpected := translate("#HISTORY")
|
||||||
|
checkStringOmits(t, output, unexpected)
|
||||||
|
unexpected = translate("Auto generated by spf13/cobra")
|
||||||
|
checkStringOmits(t, output, unexpected)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGenManSeeAlso(t *testing.T) {
|
func TestGenManSeeAlso(t *testing.T) {
|
||||||
rootCmd := &cobra.Command{Use: "root", Run: emptyRun}
|
rootCmd := &cobra.Command{Use: "root", Run: emptyRun}
|
||||||
aCmd := &cobra.Command{Use: "aaa", Run: emptyRun, Hidden: true} // #229
|
aCmd := &cobra.Command{Use: "aaa", Run: emptyRun, Hidden: true} // #229
|
||||||
|
|
Loading…
Reference in New Issue