mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
feat: add sub-command options to print support global flags
This commit is contained in:
33
cmd/kubevpn/cmds/options.go
Normal file
33
cmd/kubevpn/cmds/options.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package cmds
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
)
|
||||
|
||||
var (
|
||||
optionsExample = templates.Examples(i18n.T(`
|
||||
# Print flags inherited by all commands
|
||||
kubectl options`))
|
||||
)
|
||||
|
||||
func CmdOptions(cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "options",
|
||||
Short: i18n.T("Print the list of flags inherited by all commands"),
|
||||
Long: i18n.T("Print the list of flags inherited by all commands"),
|
||||
Example: optionsExample,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmd.Usage()
|
||||
},
|
||||
}
|
||||
|
||||
cmd.SetOut(os.Stdout)
|
||||
|
||||
templates.UseOptionsTemplates(cmd)
|
||||
return cmd
|
||||
}
|
||||
@@ -4,13 +4,17 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
)
|
||||
|
||||
func NewKubeVPNCommand() *cobra.Command {
|
||||
var cmd = &cobra.Command{
|
||||
Use: "kubevpn",
|
||||
Short: "kubevpn",
|
||||
Long: `kubevpn`,
|
||||
Short: i18n.T("kubevpn connect to Kubernetes cluster network"),
|
||||
Long: templates.LongDesc(`
|
||||
kubevpn connect to Kubernetes cluster network.
|
||||
`),
|
||||
}
|
||||
|
||||
flags := cmd.PersistentFlags()
|
||||
@@ -20,12 +24,27 @@ func NewKubeVPNCommand() *cobra.Command {
|
||||
matchVersionFlags.AddFlags(flags)
|
||||
factory := cmdutil.NewFactory(matchVersionFlags)
|
||||
|
||||
cmd.AddCommand(CmdConnect(factory))
|
||||
cmd.AddCommand(CmdReset(factory))
|
||||
cmd.AddCommand(CmdControlPlane(factory))
|
||||
cmd.AddCommand(CmdServe(factory))
|
||||
cmd.AddCommand(CmdUpgrade(factory))
|
||||
cmd.AddCommand(CmdWebhook(factory))
|
||||
cmd.AddCommand(CmdVersion(factory))
|
||||
groups := templates.CommandGroups{
|
||||
{
|
||||
Message: "Client Commands:",
|
||||
Commands: []*cobra.Command{
|
||||
CmdConnect(factory),
|
||||
CmdReset(factory),
|
||||
CmdUpgrade(factory),
|
||||
CmdVersion(factory),
|
||||
CmdOptions(factory),
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: "Server Commands (DO NOT USE IT !!!):",
|
||||
Commands: []*cobra.Command{
|
||||
CmdControlPlane(factory),
|
||||
CmdServe(factory),
|
||||
CmdWebhook(factory),
|
||||
},
|
||||
},
|
||||
}
|
||||
groups.Add(cmd)
|
||||
templates.ActsAsRootCommand(cmd, []string{"options"}, groups...)
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user