github.com/cheikhshift/buffalo@v0.9.5/buffalo/cmd/destroy/model.go (about) 1 package destroy 2 3 import ( 4 "errors" 5 "os" 6 7 "github.com/markbates/inflect" 8 "github.com/spf13/cobra" 9 ) 10 11 //ModelCmd destroys a passed model 12 var ModelCmd = &cobra.Command{ 13 Use: "model [name]", 14 //Example: "resource cars", 15 Aliases: []string{"m"}, 16 Short: "Destroys model files.", 17 RunE: func(cmd *cobra.Command, args []string) error { 18 if _, err := os.Stat(".buffalo.dev.yml"); os.IsNotExist(err) { 19 return errors.New("destroy needs to run in your buffalo project root") 20 } 21 22 if len(args) == 0 { 23 return errors.New("you need to provide a valid model name in order to destroy it") 24 } 25 26 name := args[0] 27 fileName := inflect.Pluralize(inflect.Underscore(name)) 28 29 removeModel(name) 30 removeMigrations(fileName) 31 32 return nil 33 }, 34 }