cobra.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package cmd
  2. import (
  3. "errors"
  4. "fmt"
  5. "os"
  6. "git.cestong.com.cn/cecf/hx-admin-server/cmd/app"
  7. "git.cestong.com.cn/cecf/hx-admin-server/cmd/userapi"
  8. "git.cestong.com.cn/cecf/hx-admin-server/common/global"
  9. "github.com/go-admin-team/go-admin-core/sdk/pkg"
  10. "github.com/spf13/cobra"
  11. "git.cestong.com.cn/cecf/hx-admin-server/cmd/api"
  12. "git.cestong.com.cn/cecf/hx-admin-server/cmd/config"
  13. "git.cestong.com.cn/cecf/hx-admin-server/cmd/migrate"
  14. "git.cestong.com.cn/cecf/hx-admin-server/cmd/version"
  15. )
  16. var rootCmd = &cobra.Command{
  17. Use: "cecf-hx",
  18. Short: "cecf-hx",
  19. SilenceUsage: true,
  20. Long: `cecf-hx`,
  21. Args: func(cmd *cobra.Command, args []string) error {
  22. if len(args) < 1 {
  23. tip()
  24. return errors.New(pkg.Red("requires at least one arg"))
  25. }
  26. return nil
  27. },
  28. PersistentPreRunE: func(*cobra.Command, []string) error { return nil },
  29. Run: func(cmd *cobra.Command, args []string) {
  30. tip()
  31. },
  32. }
  33. func tip() {
  34. usageStr := `欢迎使用 ` + pkg.Green(`cecf-hx `+global.Version) + ` 可以使用 ` + pkg.Red(`-h`) + ` 查看命令`
  35. fmt.Printf("%s\n", usageStr)
  36. }
  37. func init() {
  38. rootCmd.AddCommand(api.StartCmd)
  39. rootCmd.AddCommand(migrate.StartCmd)
  40. rootCmd.AddCommand(version.StartCmd)
  41. rootCmd.AddCommand(config.StartCmd)
  42. rootCmd.AddCommand(app.StartCmd)
  43. rootCmd.AddCommand(userapi.StartCmd)
  44. }
  45. //Execute : apply commands
  46. func Execute() {
  47. if err := rootCmd.Execute(); err != nil {
  48. os.Exit(-1)
  49. }
  50. }