generate

package
v4.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2018 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigCmd = &cobra.Command{
	Use:   "config",
	Short: "Generates a database.yml file for your project.",
	RunE: func(cmd *cobra.Command, args []string) error {
		cflag := cmd.Flag("config")
		cfgFile := defaults.String(cflag.Value.String(), "database.yml")
		pwd, err := os.Getwd()
		if err != nil {
			return errors.Wrap(err, "couldn't get the current directory")
		}
		data := map[string]interface{}{
			"dialect": dialect,
			"name":    filepath.Base(pwd),
		}
		return GenerateConfig(cfgFile, data)
	},
}

ConfigCmd is the command to generate pop config files

View Source
var FizzCmd = &cobra.Command{
	Use:     "fizz [name]",
	Aliases: []string{"migration"},
	Short:   "Generates Up/Down migrations for your database using fizz.",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("You must supply a name for your migration")
		}
		cflag := cmd.Flag("path")
		migrationPath := defaults.String(cflag.Value.String(), "./migrations")
		return pop.MigrationCreate(migrationPath, args[0], "fizz", nil, nil)
	},
}

FizzCmd generates a new fizz migration

View Source
var ModelCmd = &cobra.Command{
	Use:     "model [name]",
	Aliases: []string{"m"},
	Short:   "Generates a model for your database",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("You must supply a name for your model")
		}

		model := newModel(args[0])

		switch structTag {
		case "json":
			model.Imports = append(model.Imports, "encoding/json")
		case "xml":
			model.Imports = append(model.Imports, "encoding/xml")
		default:
			return errors.New("Invalid struct tags (use xml or json)")
		}

		for _, def := range args[1:] {
			a := newAttribute(def, &model)
			model.addAttribute(a)
		}

		model.addID()

		err := model.generateModelFile()
		if err != nil {
			return err
		}

		if skipMigration {
			return nil
		}

		err = model.generateFizz(cmd.Flag("path"))
		if err != nil {
			return err
		}

		return nil
	},
}

ModelCmd is the cmd to generate a model

View Source
var SQLCmd = &cobra.Command{
	Use:   "sql [name]",
	Short: "Generates Up/Down migrations for your database using SQL.",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("You must supply a name for your migration")
		}
		cflag := cmd.Flag("path")
		migrationPath := defaults.String(cflag.Value.String(), "./migrates")
		return pop.MigrationCreate(migrationPath, args[0], "sql", nil, nil)
	},
}

SQLCmd generates a SQL migration

Functions

func GenerateConfig

func GenerateConfig(cfgFile string, data map[string]interface{}) error

GenerateConfig generates pop configuration files

Types

This section is empty.

Jump to

Keyboard shortcuts

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