cmd

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Conf       = "./cmd/conf/db.toml"
	Out        = "./models"
	NewCRUDCmd = &cobra.Command{
		Use:   "new-crud",
		Short: "Create the model code for the CRUD.",
		Long:  `Create the model code for the CRUD, You can view subcommands and customize builds`,
		RunE: func(cmd *cobra.Command, args []string) (err error) {
			tl := crud.CrudTemplate()
			s2 := crud.NewTable2Struct()
			dc := DBConf{}
			if err = configure(&dc, Conf); err != nil {
				return
			}
			list, err := s2.Dsn(dc.Addr).Run()
			if err != nil {
				return err
			}
			for index := 0; index < len(list); index++ {
				pdata := map[string]interface{}{
					"Name":    list[index].Name,
					"Content": list[index].Content,
				}

				var pf *os.File
				pf, err = os.Create(Out + "/" + list[index].TableRealName + ".go")
				if err != nil {
					return err
				}
				tmpl, err := template.New("").Parse(tl)
				if err = tmpl.Execute(pf, pdata); err != nil {
					return err
				}
			}
			exec.Command("gofmt", "-w", Out).Output()

			return nil
		}}
)
View Source
var (
	NewProjectCmd = &cobra.Command{
		Use:   "new-project [project_name]",
		Short: "New a microservice project based on freedom",
		Long:  `New project from freedom project template. `,
		RunE: func(cmd *cobra.Command, args []string) (err error) {
			sysPath, err := filepath.Abs(args[0])
			if err != nil {
				return
			}

			projectPath := strings.Replace(sysPath, build.Default.GOPATH+"/src/", "", 1)
			projectName := args[0]
			pdata := map[string]interface{}{
				"PackagePath": projectPath,
				"PackageName": projectName,
			}

			mkdirAll(sysPath)
			m := project.FileContent()
			for filepath, content := range m {
				var pf *os.File
				pf, err = os.Create(sysPath + filepath)
				if err != nil {
					return err
				}
				tmpl, err := template.New(projectName).Parse(content)
				if err = tmpl.Execute(pf, pdata); err != nil {
					return err
				}
			}
			exec.Command("gofmt", "-w", sysPath).Output()
			return nil
		},
	}
)

Functions

func AddCommand

func AddCommand(cmd *cobra.Command)

AddCommand add sub command to root

func Commands

func Commands() []*cobra.Command

Commands returns all sub command

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

type DBConf added in v1.0.0

type DBConf struct {
	Addr string `toml:"addr"`
}

Jump to

Keyboard shortcuts

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