initcmd

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CMD = func() *cli.Command {

	// 项目名
	var name string

	return &cli.Command{
		Name:  "init",
		Usage: "init a project.",
		Action: func(ctx *cli.Context) error {

			if name == "" {
				return errors.New("must a name")
			}

			if err := conf.WriteConf(conf.Conf{
				ModName: name,
			}); err != nil {
				return err
			}

			for _, dir := range dirs {
				if err := os.MkdirAll(dir, os.ModePerm); err != nil {
					return err
				}
			}

			if err := os.MkdirAll(filepath.Join("internal", "pb", "proto"), os.ModePerm); err != nil {
				return err
			}

			gitignFile, err := os.Create(".gitignore")
			if err != nil {
				return err
			}
			defer gitignFile.Close()

			if _, err := gitignFile.WriteString(gitignoreText); err != nil {
				return err
			}

			gomodCmd := exec.Command("go", "mod", "init", name)
			_, err = gomodCmd.Output()
			if err != nil {
				return err
			}

			return nil
		},
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:        "name",
				Usage:       "project name",
				Destination: &name,
			},
		},
	}
}

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