crud

package
v0.2.14 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "crud [flags]",
	Short: "Generate CRUD source code of type",
	Args: func(cmd *cobra.Command, args []string) error {
		if name == "" {
			return errors.New("need the type name")
		}
		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {

		if pkgname == "" {
			i, err := build.Import(".", ".", 0)
			if err == nil {
				pkgname = i.Name
			}
		}

		if pkgname == "" {
			pkgname = "main"
		}

		g := crud.NewGenCrud()
		data, err := g.Generate(tplname, pkgname, name)
		if err != nil {
			return err
		}

		if out == "" {
			out = namecase.ToLowerSnake(name) + ".go"
		}

		if data0, err := format.Source(data); err == nil {
			data = data0
		}

		err = ioutil.WriteFile(out, data, 0666)
		if err != nil {
			return err
		}

		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