Files
go-admin/cmd/cobra.go
T

51 lines
1.1 KiB
Go
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package cmd
import (
"errors"
"fmt"
"github.com/spf13/cobra"
"go-admin/cmd/api"
"go-admin/cmd/migrate"
"go-admin/global"
"go-admin/tools"
"os"
)
var rootCmd = &cobra.Command{
Use: "go-admin",
Short: "-v",
SilenceUsage: true,
DisableAutoGenTag: true,
Long: `go-admin`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
tip()
return errors.New(tools.Red("requires at least one arg"))
}
return nil
},
PersistentPreRunE: func(*cobra.Command, []string) error { return nil },
Run: func(cmd *cobra.Command, args []string) {
tip()
},
}
func tip() {
usageStr := `欢迎使用 `+ tools.Green( `go-admin ` +global.Version) + ` 可以使用 ` + tools.Red(`-h`) + ` 查看命令`
usageStr1 := `也可以参考 http://doc.zhangwj.com/go-admin-site/guide/ksks.html 里边的【启动】章节`
fmt.Printf("%s\n", usageStr)
fmt.Printf("%s\n", usageStr1)
}
func init() {
rootCmd.AddCommand(api.StartCmd)
rootCmd.AddCommand(migrate.StartCmd)
}
//Execute : apply commands
func Execute() {
if err := rootCmd.Execute(); err != nil {
os.Exit(-1)
}
}