cmd

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Module = &gcmd.Command{
		Name:        "module",
		Usage:       "cool-tools module moduleName",
		Brief:       "在modules目录下创建模块",
		Description: "在modules目录下创建模块, 并且创建相应的目录结构,注意: 如果模块已经存在, 则会覆盖原有的模块,本命令需在项目根目录下执行.",
		Arguments: []gcmd.Argument{
			{
				Name:   "moduleName",
				IsArg:  true,
				Orphan: false,
			},
		},
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			moduleName := parser.GetArg(2).String()
			if moduleName == "" {
				println("moduleName is empty")
				return nil
			}
			err = service.CreatModule(ctx, moduleName)
			return
		},
	}
	M = &gcmd.Command{
		Name:        "m",
		Usage:       "cool-tools module moduleName",
		Brief:       "在modules目录下创建模块,为module的简写模式",
		Description: "在modules目录下创建模块, 并且创建相应的目录结构,注意: 如果模块已经存在, 则会覆盖原有的模块,本命令需在项目根目录下执行.",
		Arguments: []gcmd.Argument{
			{
				Name:   "moduleName",
				IsArg:  true,
				Orphan: false,
			},
		},
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			moduleName := parser.GetArg(2).String()
			if moduleName == "" {
				println("moduleName is empty")
				return nil
			}
			err = service.CreatModule(ctx, moduleName)
			return
		},
	}
)
View Source
var (
	Dump = &gcmd.Command{
		Name:        "dump",
		Usage:       "cool-tools dump",
		Brief:       "查看打包的资源文件",
		Description: "查看打包的资源文件",
		Arguments:   []gcmd.Argument{},
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			gres.Dump()
			return nil
		},
	}
)
View Source
var (
	Gen = cGen{}
)
View Source
var (
	GenModel = cGenModel{}
)
View Source
var (
	Init = gcmd.Command{
		Name:  "init",
		Usage: "cool-tools init [dst]",
		Brief: "创建一个新的cool-admin-go项目",
		Arguments: []gcmd.Argument{
			{
				Name: "dst",

				Brief: "the destination path",
				IsArg: true,
			},
		},
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			dst := parser.GetArg(2).String()
			if dst == "" {
				dst = "."
			}

			if gfile.IsEmpty(dst) {
				if err = gfile.Mkdir(dst); err != nil {
					return
				}
			} else {
				if !gfile.IsDir(dst) {
					g.Log().Panicf(ctx, "%s is not a directory", dst)
				} else {
					s := gcmd.Scanf(`the folder "%s" is not empty, files might be overwrote, continue? [y/n]: `, dst)
					if strings.EqualFold(s, "n") {
						return
					}

				}
			}

			err = gres.Export("cool-admin-go-simple", dst, gres.ExportOption{
				RemovePrefix: "cool-admin-go-simple",
			})
			if err != nil {
				return
			}

			err = gfile.ReplaceDir("cool-admin-go-simple", gfile.Basename(gfile.RealPath(dst)), dst, "*", true)
			if err != nil {
				return
			}
			g.Log().Infof(ctx, "init success")
			return nil
		},
	}
)
View Source
var (
	Install = gcmd.Command{
		Name:  "install",
		Usage: "cool-tools install",
		Brief: "Install cool-tools to the system.",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			err = service.Install.Run(ctx)
			return
		},
	}
)
View Source
var (
	Main = gcmd.Command{
		Name:        "cool-tools",
		Usage:       "cool-tools [command] [args...]",
		Brief:       "cool-tools is a collection of tools for cool people.",
		Description: `cool-tools is a collection of tools for cool people.`,
	}
)
View Source
var (
	SnippetsMaker = gcmd.Command{
		Name:  "snippetsmaker",
		Usage: "snippetsmaker",
		Brief: "代码片段生成器",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			g.Log().Debug(ctx, "snippetsmaker,生成工具^.^")
			files := garray.New(true)
			files.Append("modules/demo/model/demo_sample.go")
			files.Append("modules/demo/service/demo_sample.go")
			files.Append("modules/demo/controller/admin/demo_sample.go")

			for _, file := range files.Slice() {
				sArray := garray.NewStrArray()
				gfile.ReadLines(file.(string), func(line string) error {

					replaceArray := []string{"DemoSample", "${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}", "demo_sample", "${TM_FILENAME_BASE/(.*)/${1:/downcase}/}"}

					result := gstr.ReplaceByArray(line, replaceArray)
					sArray.Append(gstr.AddSlashes(result))

					return nil
				})

				println(file.(string))
				println("--------------------------------------code start------------------------------------------")
				println(`"body":[`)
				sArray.Iterator(
					func(index int, value string) bool {
						println("\"" + value + "\",")
						return true
					},
				)
				println("]")
				println("--------------------------------------code end------------------------------------------")
			}
			return nil
		},
	}
)
View Source
var (
	Version = gcmd.Command{
		Name:  "version",
		Usage: "cool-tools version",
		Brief: "查看版本信息",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			info := gbuild.Info()

			data := gbuild.Data()

			var binVersion string
			if len(data) == 0 || data["version"] == nil {
				binVersion = "dev"
			} else {
				binVersion = data["version"].(string)
			}

			res := sVersion{
				Name:     "cool-tools",
				Homepage: "https://cool-js.com",
				Version:  binVersion,
				GoFrame:  info.GoFrame,
				Golang:   info.Golang,
				Git:      info.Git,
				Time:     info.Time,
			}
			mlog.Printf(`CLI Installed At: %s`, gfile.SelfPath())
			gutil.Dump(res)
			return nil
		},
	}
)

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