Skip to content

Commit

Permalink
doc: check error return values
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor committed Jun 7, 2019
1 parent 1dad236 commit 23302d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
28 changes: 14 additions & 14 deletions doc/man_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,25 @@ func fillHeader(header *GenManHeader, name string) error {
return nil
}

func manPreamble(buf *bytes.Buffer, header *GenManHeader, cmd *cobra.Command, dashedName string) {
func manPreamble(buf io.StringWriter, header *GenManHeader, cmd *cobra.Command, dashedName string) {
description := cmd.Long
if len(description) == 0 {
description = cmd.Short
}

buf.WriteString(fmt.Sprintf(`%% %s(%s)%s
wrStringAndCheck(buf, fmt.Sprintf(`%% %s(%s)%s
%% %s
%% %s
# NAME
`, header.Title, header.Section, header.date, header.Source, header.Manual))
buf.WriteString(fmt.Sprintf("%s \\- %s\n\n", dashedName, cmd.Short))
buf.WriteString("# SYNOPSIS\n")
buf.WriteString(fmt.Sprintf("**%s**\n\n", cmd.UseLine()))
buf.WriteString("# DESCRIPTION\n")
buf.WriteString(description + "\n\n")
wrStringAndCheck(buf, fmt.Sprintf("%s \\- %s\n\n", dashedName, cmd.Short))
wrStringAndCheck(buf, "# SYNOPSIS\n")
wrStringAndCheck(buf, fmt.Sprintf("**%s**\n\n", cmd.UseLine()))
wrStringAndCheck(buf, "# DESCRIPTION\n")
wrStringAndCheck(buf, description+"\n\n")
}

func manPrintFlags(buf *bytes.Buffer, flags *pflag.FlagSet) {
func manPrintFlags(buf io.StringWriter, flags *pflag.FlagSet) {
flags.VisitAll(func(flag *pflag.Flag) {
if len(flag.Deprecated) > 0 || flag.Hidden {
return
Expand All @@ -181,22 +181,22 @@ func manPrintFlags(buf *bytes.Buffer, flags *pflag.FlagSet) {
format += "]"
}
format += "\n\t%s\n\n"
buf.WriteString(fmt.Sprintf(format, flag.DefValue, flag.Usage))
wrStringAndCheck(buf, fmt.Sprintf(format, flag.DefValue, flag.Usage))
})
}

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

Expand Down
2 changes: 1 addition & 1 deletion doc/man_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestGenManSeeAlso(t *testing.T) {
func TestManPrintFlagsHidesShortDeperecated(t *testing.T) {
c := &cobra.Command{}
c.Flags().StringP("foo", "f", "default", "Foo flag")
c.Flags().MarkShorthandDeprecated("foo", "don't use it no more")
er(c.Flags().MarkShorthandDeprecated("foo", "don't use it no more"))

buf := new(bytes.Buffer)
manPrintFlags(buf, c.Flags())
Expand Down
4 changes: 2 additions & 2 deletions doc/man_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ExampleGenManTree() {
Title: "MINE",
Section: "3",
}
doc.GenManTree(cmd, header, "/tmp")
er(doc.GenManTree(cmd, header, "/tmp"))
}

func ExampleGenMan() {
Expand All @@ -34,6 +34,6 @@ func ExampleGenMan() {
Section: "3",
}
out := new(bytes.Buffer)
doc.GenMan(cmd, header, out)
er(doc.GenMan(cmd, header, out))
fmt.Print(out.String())
}

0 comments on commit 23302d0

Please sign in to comment.