sqlboiler/cmds/structs.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

47 lines
1,019 B
Go

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