1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 07:57:07 +00:00
kyverno/cmd/cli/kubectl-kyverno/commands/docs/options.go
Charles-Edouard Brétéché d24b0848a6
chore: add cli commands unit tests (#8366)
* chore: add cli unit tests

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* chore: add cli commands unit tests

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-12 21:47:03 +00:00

41 lines
831 B
Go

package docs
import (
"errors"
"os"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
type options struct {
path string
website bool
autogenTag bool
}
func (o options) validate(root *cobra.Command) error {
if o.path == "" {
return errors.New("path is required")
}
if root == nil {
return errors.New("root command is required")
}
return nil
}
func (o options) execute(root *cobra.Command) error {
prepender := empty
linkHandler := identity
if o.website {
prepender = websitePrepender
linkHandler = websiteLinkHandler
}
if _, err := os.Stat(o.path); errors.Is(err, os.ErrNotExist) {
if err := os.MkdirAll(o.path, os.ModeDir|os.ModePerm); err != nil {
return err
}
}
root.DisableAutoGenTag = !o.autogenTag
return doc.GenMarkdownTreeCustom(root, o.path, prepender, linkHandler)
}