mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
clair vele help cli
Signed-off-by: Weiping Cai <weiping.cai@daocloud.io>
This commit is contained in:
+1
-13
@@ -81,6 +81,7 @@ func NewCommand() *cobra.Command {
|
||||
NewDashboardCommand(commandArgs, ioStream, fake.FrontendSource),
|
||||
NewCompletionCommand(),
|
||||
NewVersionCommand(),
|
||||
NewHelpCommand(),
|
||||
)
|
||||
|
||||
// this is for mute klog
|
||||
@@ -91,19 +92,6 @@ func NewCommand() *cobra.Command {
|
||||
return cmds
|
||||
}
|
||||
|
||||
// PrintHelpByTag print custom defined help message
|
||||
func PrintHelpByTag(cmd *cobra.Command, all []*cobra.Command, tag string) {
|
||||
cmd.Printf(" %s:\n\n", tag)
|
||||
table := newUITable()
|
||||
for _, c := range all {
|
||||
if val, ok := c.Annotations[types.TagCommandType]; ok && val == tag {
|
||||
table.AddRow(" "+c.Use, c.Long)
|
||||
}
|
||||
}
|
||||
cmd.Println(table.String())
|
||||
cmd.Println()
|
||||
}
|
||||
|
||||
// NewVersionCommand print client version
|
||||
func NewVersionCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/oam-dev/kubevela/apis/types"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewHelpCommand get any command help
|
||||
func NewHelpCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "help [command] ",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: "Help about any command",
|
||||
Run: RunHelp,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
// RunHelp exec help [command]
|
||||
func RunHelp(cmd *cobra.Command, args []string) {
|
||||
if len(args) == 0 {
|
||||
allCommands := cmd.Root().Commands()
|
||||
// print error message at first, since it can contain suggestions
|
||||
cmd.Printf("A Highly Extensible Platform Engine based on Kubernetes and Open Application Model.\n\nUsage:\n vela [flags]\n vela [command]\n\nAvailable Commands:\n\n")
|
||||
PrintHelpByTag(cmd, allCommands, types.TypeStart)
|
||||
PrintHelpByTag(cmd, allCommands, types.TypeApp)
|
||||
PrintHelpByTag(cmd, allCommands, types.TypeCap)
|
||||
PrintHelpByTag(cmd, allCommands, types.TypeSystem)
|
||||
} else {
|
||||
foundCmd, _, err := cmd.Root().Find(args)
|
||||
if foundCmd != nil && err == nil {
|
||||
foundCmd.HelpFunc()(cmd, args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PrintHelpByTag print custom defined help message
|
||||
func PrintHelpByTag(cmd *cobra.Command, all []*cobra.Command, tag string) {
|
||||
cmd.Printf(" %s:\n\n", tag)
|
||||
table := newUITable()
|
||||
for _, c := range all {
|
||||
if val, ok := c.Annotations[types.TagCommandType]; ok && val == tag {
|
||||
table.AddRow(" "+c.Use, c.Long)
|
||||
}
|
||||
}
|
||||
cmd.Println(table.String())
|
||||
cmd.Println()
|
||||
}
|
||||
Reference in New Issue
Block a user