make_factory.go 465 B

1234567891011121314151617181920212223
  1. package make
  2. import (
  3. "fmt"
  4. "github.com/spf13/cobra"
  5. )
  6. var CmdMakeFactory = &cobra.Command{
  7. Use: "factory",
  8. Short: "Create model's factory file, example: make factory user",
  9. Run: runMakeFactory,
  10. Args: cobra.ExactArgs(1),
  11. }
  12. func runMakeFactory(cmd *cobra.Command, args []string) {
  13. model := makeModelFromString(args[0])
  14. filePath := fmt.Sprintf("database/factories/%s_factory.go", model.PackageName)
  15. createFileFromTpl(filePath, "factory", model)
  16. }