Cleanup
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
Родитель
8a505799c6
Коммит
70265e4072
|
@ -1,7 +1,6 @@
|
|||
[![PkgGoDev](https://img.shields.io/badge/go.dev-docs-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/docker/docgen)
|
||||
[![Test Status](https://img.shields.io/github/workflow/status/crazy-max/docgen/build?label=build&logo=github&style=flat-square)](https://github.com/docker/docgen/actions?query=workflow%3Atest)
|
||||
[![Go Report Card](https://goreportcard.com/badge/github.com/docker/docgen)](https://goreportcard.com/report/github.com/docker/docgen)
|
||||
[![Codecovs](https://img.shields.io/codecov/c/github/crazy-max/docgen?logo=codecov&style=flat-square)](https://codecov.io/gh/crazy-max/docgen)
|
||||
|
||||
## About
|
||||
|
||||
|
|
22
cobra.go
22
cobra.go
|
@ -1,22 +0,0 @@
|
|||
package docgen
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
// VisitAll will traverse all commands from the root.
|
||||
// This is different from the VisitAll of cobra.Command where only parents
|
||||
// are checked.
|
||||
func VisitAll(root *cobra.Command, fn func(*cobra.Command)) {
|
||||
for _, cmd := range root.Commands() {
|
||||
VisitAll(cmd, fn)
|
||||
}
|
||||
fn(root)
|
||||
}
|
||||
|
||||
// DisableFlagsInUseLine sets the DisableFlagsInUseLine flag on all
|
||||
// commands within the tree rooted at cmd.
|
||||
func DisableFlagsInUseLine(cmd *cobra.Command) {
|
||||
VisitAll(cmd, func(ccmd *cobra.Command) {
|
||||
// do not add a `[flags]` to the end of the usage line.
|
||||
ccmd.DisableFlagsInUseLine = true
|
||||
})
|
||||
}
|
22
docgen.go
22
docgen.go
|
@ -4,6 +4,9 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// GenTree creates yaml and markdown structured ref files for this command
|
||||
// and all descendants in the directory given. This function will just
|
||||
// call GenMarkdownTree and GenYamlTree functions successively.
|
||||
func GenTree(cmd *cobra.Command, dir string) error {
|
||||
var err error
|
||||
if err = GenMarkdownTree(cmd, dir); err != nil {
|
||||
|
@ -14,3 +17,22 @@ func GenTree(cmd *cobra.Command, dir string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// VisitAll will traverse all commands from the root.
|
||||
// This is different from the VisitAll of cobra.Command where only parents
|
||||
// are checked.
|
||||
func VisitAll(root *cobra.Command, fn func(*cobra.Command)) {
|
||||
for _, cmd := range root.Commands() {
|
||||
VisitAll(cmd, fn)
|
||||
}
|
||||
fn(root)
|
||||
}
|
||||
|
||||
// DisableFlagsInUseLine sets the DisableFlagsInUseLine flag on all
|
||||
// commands within the tree rooted at cmd.
|
||||
func DisableFlagsInUseLine(cmd *cobra.Command) {
|
||||
VisitAll(cmd, func(ccmd *cobra.Command) {
|
||||
// do not add a `[flags]` to the end of the usage line.
|
||||
ccmd.DisableFlagsInUseLine = true
|
||||
})
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче