fix: correct command path in see_also for YAML doc

The `see_also` section for child commands would include only the name of
command. This adds the whole path, similar to how it's done for the
other documentation formats.
This commit is contained in:
Zoran Regvart 2022-08-04 15:46:04 +02:00
parent 162534f92f
commit e8f9808db6
No known key found for this signature in database
GPG key ID: 6D9197EFE5AB7D75
2 changed files with 3 additions and 1 deletions

View file

@ -128,7 +128,7 @@ func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) str
if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() { if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() {
continue continue
} }
result = append(result, child.Name()+" - "+child.Short) result = append(result, child.CommandPath()+" - "+child.Short)
} }
yamlDoc.SeeAlso = result yamlDoc.SeeAlso = result
} }

View file

@ -2,6 +2,7 @@ package doc
import ( import (
"bytes" "bytes"
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -24,6 +25,7 @@ func TestGenYamlDoc(t *testing.T) {
checkStringContains(t, output, "rootflag") checkStringContains(t, output, "rootflag")
checkStringContains(t, output, rootCmd.Short) checkStringContains(t, output, rootCmd.Short)
checkStringContains(t, output, echoSubCmd.Short) checkStringContains(t, output, echoSubCmd.Short)
checkStringContains(t, output, fmt.Sprintf("- %s - %s", echoSubCmd.CommandPath(), echoSubCmd.Short))
} }
func TestGenYamlNoTag(t *testing.T) { func TestGenYamlNoTag(t *testing.T) {