mirror of
https://github.com/spf13/cobra
synced 2025-04-01 20:39:12 +00:00
Merge 83d142ca76
into ceb39aba25
This commit is contained in:
commit
0232a4b25f
3 changed files with 14 additions and 1 deletions
|
@ -103,3 +103,10 @@ func checkStringOmits(t *testing.T, got, expected string) {
|
|||
t.Errorf("Expected to not contain: \n %v\nGot: %v", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func checkStringOmitsSuffix(t *testing.T, got, expected string) {
|
||||
if strings.HasSuffix(got, expected) {
|
||||
// Note this uses %q so things like line breaks can be seen in the printed output
|
||||
t.Errorf("Expected to not have suffix: \n %q\nGot: %q", expected, got)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,9 +107,9 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
|
|||
link = strings.ReplaceAll(link, " ", "_")
|
||||
buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", cname, linkHandler(link), child.Short))
|
||||
}
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
if !cmd.DisableAutoGenTag {
|
||||
buf.WriteString("\n")
|
||||
buf.WriteString("###### Auto generated by spf13/cobra on " + time.Now().Format("2-Jan-2006") + "\n")
|
||||
}
|
||||
_, err := buf.WriteTo(w)
|
||||
|
|
|
@ -23,6 +23,8 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const doubleLineBreak = "\n\n"
|
||||
|
||||
func TestGenMdDoc(t *testing.T) {
|
||||
// We generate on subcommand so we have both subcommands and parents.
|
||||
buf := new(bytes.Buffer)
|
||||
|
@ -39,6 +41,7 @@ func TestGenMdDoc(t *testing.T) {
|
|||
checkStringContains(t, output, echoSubCmd.Short)
|
||||
checkStringOmits(t, output, deprecatedCmd.Short)
|
||||
checkStringContains(t, output, "Options inherited from parent commands")
|
||||
checkStringOmitsSuffix(t, output, doubleLineBreak)
|
||||
}
|
||||
|
||||
func TestGenMdDocWithNoLongOrSynopsis(t *testing.T) {
|
||||
|
@ -53,6 +56,7 @@ func TestGenMdDocWithNoLongOrSynopsis(t *testing.T) {
|
|||
checkStringContains(t, output, dummyCmd.Short)
|
||||
checkStringContains(t, output, "Options inherited from parent commands")
|
||||
checkStringOmits(t, output, "### Synopsis")
|
||||
checkStringOmitsSuffix(t, output, doubleLineBreak)
|
||||
}
|
||||
|
||||
func TestGenMdNoHiddenParents(t *testing.T) {
|
||||
|
@ -76,6 +80,7 @@ func TestGenMdNoHiddenParents(t *testing.T) {
|
|||
checkStringContains(t, output, echoSubCmd.Short)
|
||||
checkStringOmits(t, output, deprecatedCmd.Short)
|
||||
checkStringOmits(t, output, "Options inherited from parent commands")
|
||||
checkStringOmitsSuffix(t, output, doubleLineBreak)
|
||||
}
|
||||
|
||||
func TestGenMdNoTag(t *testing.T) {
|
||||
|
@ -89,6 +94,7 @@ func TestGenMdNoTag(t *testing.T) {
|
|||
output := buf.String()
|
||||
|
||||
checkStringOmits(t, output, "Auto generated")
|
||||
checkStringOmitsSuffix(t, output, doubleLineBreak)
|
||||
}
|
||||
|
||||
func TestGenMdTree(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue