commands

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Generator = cli.Command{
	Name: "gen",
	Subcommands: []*cli.Command{
		{
			Name:   "config",
			Usage:  "生成工具所需的配置文件",
			Action: actions.GenConfig,
			After: func(context *cli.Context) error {
				fmt.Println("配置文件已生成,注意修改项目对应值")
				return nil
			},
		},
		{
			Name:  "project",
			Usage: "生成项目目录结构",
			Before: func(context *cli.Context) error {
				_, err := utils.GetProjectConfig()
				if err != nil {
					err = errors.New(err.Error())
					return err
				}
				return nil
			},
			Action: actions.GenProject,
		},
		{
			Name: "db",
			Before: func(context *cli.Context) error {
				_, err := utils.GetProjectConfig()
				if err != nil {
					err = errors.New(err.Error())
					return err
				}
				return nil
			},
			Action: actions.GenDatabase,
			Usage:  "生成数据库模型及常用的CURD操作",
		},
		{
			Name: "services",
			Before: func(context *cli.Context) error {
				_, err := utils.GetProjectConfig()
				if err != nil {
					err = errors.New(err.Error())
					return err
				}
				return nil
			},
			Action: actions.GenServices,
			Usage:  "生成参数接收、验证相关结构体",
		},
		{
			Name: "controller",
			Before: func(context *cli.Context) error {
				_, err := utils.GetProjectConfig()
				if err != nil {
					err = errors.New(err.Error())
					return err
				}
				return nil
			},
			Action: actions.GenController,
			Usage:  "生成控制器",
		},
	},
	Usage:     "generate file.",
	UsageText: "生成的父级命令",
	After: func(context *cli.Context) error {
		fmt.Println("🤪done!")
		return nil
	},
}

Generator 生成命令

View Source
var Update = cli.Command{
	Name:    "update",
	Aliases: []string{"up"},
	Before: func(context *cli.Context) error {
		if _, err := os.Stat("cli.yaml"); err != nil {
			fmt.Println("请先执行gen-cli gen config")
			os.Exit(2)
		}

		viper.SetConfigName("cli")
		viper.SetConfigType("yaml")
		viper.AddConfigPath(".")
		err := viper.ReadInConfig()
		if err != nil {
			return err
		}
		return nil
	},
	Action: func(context *cli.Context) error {

		command := exec.Command("go", "install", "gitee.com/eddy87/gin-cli@latest")
		info, err := command.CombinedOutput()
		if err != nil {
			fmt.Println("升级出现问题", info)
			return err
		}
		fmt.Println("升级成功")
		return nil
	},
}

Update 生成命令

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL