sqlboiler/cmds/delete.go
Patrick O'brien 47c5be1038 Removed unused test files, added comments to cmds
* Added comments to all cmds files
* Removed unused test files
* Removed unimplemented command 'update'
2016-02-24 18:53:34 +10:00

46 lines
999 B
Go

package cmds
import (
"text/template"
"github.com/spf13/cobra"
)
// init the "delete" command
func init() {
SQLBoiler.AddCommand(deleteCmd)
deleteCmd.Run = deleteRun
}
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Generate delete statement helpers from table definitions",
}
// deleteRun executes the delete command, and generates the delete statement
// boilerplate from the template file.
func deleteRun(cmd *cobra.Command, args []string) {
err := outHandler(generateDeletes())
if err != nil {
errorQuit(err)
}
}
// generateDeletes returns a slice of each template execution result.
// Each of these results holds a delete statement generated from the delete template.
func generateDeletes() [][]byte {
t, err := template.New("delete.tpl").Funcs(template.FuncMap{
"makeGoColName": makeGoColName,
}).ParseFiles("templates/delete.tpl")
if err != nil {
errorQuit(err)
}
outputs, err := processTemplate(t)
if err != nil {
errorQuit(err)
}
return outputs
}