kuma
53 строки · 1.4 Кб
1package cmd
2
3import (
4"os"
5
6"github.com/spf13/cobra"
7)
8
9type args struct {
10pluginDir string
11version string
12goModule string
13}
14
15func newRootCmd() *cobra.Command {
16rootArgs := &args{}
17
18cmd := &cobra.Command{
19Use: "policy-gen",
20Short: "Tool to generate plugin-based policies for Kuma",
21Long: "Tool to generate plugin-based policies for Kuma.",
22PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
23// once command line flags have been parsed,
24// avoid printing usage instructions
25cmd.SilenceUsage = true
26return nil
27},
28}
29
30cmd.AddCommand(newCoreResource(rootArgs))
31cmd.AddCommand(newK8sResource(rootArgs))
32cmd.AddCommand(newOpenAPI(rootArgs))
33cmd.AddCommand(newPluginFile(rootArgs))
34cmd.AddCommand(newHelpers(rootArgs))
35
36cmd.PersistentFlags().StringVar(&rootArgs.pluginDir, "plugin-dir", "", "path to the policy plugin director")
37cmd.PersistentFlags().StringVar(&rootArgs.version, "version", "v1alpha1", "policy version")
38cmd.PersistentFlags().StringVar(&rootArgs.goModule, "gomodule", "github.com/kumahq/kuma", "Where to put the generated code")
39
40return cmd
41}
42
43func DefaultRootCmd() *cobra.Command {
44return newRootCmd()
45}
46
47// Execute adds all child commands to the root command and sets flags appropriately.
48// This is called by main.main(). It only needs to happen once to the rootCmd.
49func Execute() {
50if err := DefaultRootCmd().Execute(); err != nil {
51os.Exit(1)
52}
53}
54