mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
* 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>
41 lines
831 B
Go
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)
|
|
}
|