feat: improve docs output
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
Former-commit-id: af19a86cebfe955619d5e05cfd5e9c4101a328e0 [formerly 84df35184bd684e00617651b0115b219e6e9c88e] [formerly 697906b1c6c4e47a03518edd50f5e3d86ea16690 [formerly ebaed3c390
]]
Former-commit-id: a89ca0fd17984ebf6e95596ed515ad1592d314b6 [formerly e776a061d2628054eca107076601703aa2c7575d]
Former-commit-id: 7c809138219ef4723ec1ae47252eacdb60f7d78d
pull/726/head
parent
f70fc2d954
commit
c59d42b601
22
cmd/docs.go
22
cmd/docs.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/pflag"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -110,20 +111,29 @@ func generateMarkdown(cmd *cobra.Command, w io.Writer) {
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateFlagsTable(fs *pflag.FlagSet, buf *bytes.Buffer) {
|
||||||
|
buf.WriteString("| Name | Shorthand | Usage |\n")
|
||||||
|
buf.WriteString("|------|-----------|-------|\n")
|
||||||
|
|
||||||
|
fs.VisitAll(func(f *pflag.Flag) {
|
||||||
|
buf.WriteString("|" + f.Name + "|" + f.Shorthand + "|" + f.Usage + "|\n")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func printOptions(buf *bytes.Buffer, cmd *cobra.Command, name string) {
|
func printOptions(buf *bytes.Buffer, cmd *cobra.Command, name string) {
|
||||||
flags := cmd.NonInheritedFlags()
|
flags := cmd.NonInheritedFlags()
|
||||||
flags.SetOutput(buf)
|
flags.SetOutput(buf)
|
||||||
if flags.HasAvailableFlags() {
|
if flags.HasAvailableFlags() {
|
||||||
buf.WriteString("## Options\n\n```\n")
|
buf.WriteString("## Options\n\n")
|
||||||
flags.PrintDefaults()
|
generateFlagsTable(flags, buf)
|
||||||
buf.WriteString("```\n\n")
|
buf.WriteString("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
parentFlags := cmd.InheritedFlags()
|
parentFlags := cmd.InheritedFlags()
|
||||||
parentFlags.SetOutput(buf)
|
parentFlags.SetOutput(buf)
|
||||||
if parentFlags.HasAvailableFlags() {
|
if parentFlags.HasAvailableFlags() {
|
||||||
buf.WriteString("### Inherited\n\n```\n")
|
buf.WriteString("### Inherited\n\n")
|
||||||
parentFlags.PrintDefaults()
|
generateFlagsTable(parentFlags, buf)
|
||||||
buf.WriteString("```\n")
|
buf.WriteString("\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue