cmd

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Module = &gcmd.Command{
		Name:        "module",
		Usage:       "vgo-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:       "vgo-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 (
	Build = cBuild{
		// contains filtered or unexported fields
	}
)
View Source
var (
	Docs = gcmd.Command{
		Name:        "docs",
		Usage:       "vgo-tools docs",
		Brief:       "查看帮助文档",
		Description: "查看帮助文档",
		Func: func(ctx context.Context, parser *gcmd.Parser) error {
			s := g.Server("docs")

			port, err := getfreeport()
			if err != nil {
				mlog.Fatal(err)
				return err
			}

			s.SetServerRoot("docs")
			s.BindHandler("/", func(r *ghttp.Request) {
				r.Response.RedirectTo("/vgo/")
			})

			s.SetPort(gconv.Int(port))
			mlog.Printf("Vgo docs server is running at %s", "http://"+"127.0.0.1"+":"+gconv.String(port)+"/vgo/")
			s.Run()
			return nil
		},
	}
)
View Source
var (
	Dump = &gcmd.Command{
		Name:        "dump",
		Usage:       "vgo-tools dump",
		Brief:       "查看打包的资源文件",
		Description: "查看打包的资源文件",
		Arguments:   []gcmd.Argument{},
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			gres.Dump()
			return nil
		},
	}
)
View Source
var (
	Init = gcmd.Command{
		Name:  "init",
		Usage: "vgo-tools init [dst]",
		Brief: "创建一个新的vgo项目",
		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("vgo-simple", dst, gres.ExportOption{
				RemovePrefix: "vgo-simple",
			})
			if err != nil {
				return
			}

			err = gfile.ReplaceDir("vgo-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: "vgo-tools install",
		Brief: "Install vgo-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:        "vgo-tools",
		Usage:       "vgo-tools [command] [args...]",
		Brief:       "vgo-tools is a collection of tools for v people.",
		Description: `vgo-tools is a collection of tools for v people.`,
	}
)
View Source
var (
	Pack = cPack{}
)
View Source
var (
	Run = cRun{}
)
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: "vgo-tools version",
		Brief: "查看版本信息",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			info := gbuild.Info()
			binVersion := "v1.0.11"

			res := sVersion{
				Name:        "vgo-tools",
				Homepage:    "https://github.com/vera-byte/vgo",
				Version:     binVersion,
				GoFrame:     info.GoFrame,
				Golang:      info.Golang,
				Git:         info.Git,
				Time:        info.Time,
				InstallPath: gfile.SelfDir(),
			}

			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