sqlboiler/cmds/boil.go
Patrick O'brien 195e8d16e8 Broke up all commands into individual templates.
* Added bunch of new command names and descriptions.
* Changed "all" command to "boil", so we can use "all"
  for the name of the all database select helper.
2016-02-29 21:45:28 +10:00

55 lines
1.3 KiB
Go

package cmds
import (
"sort"
"github.com/spf13/cobra"
)
var boilCmd = &cobra.Command{
Use: "boil",
Short: "Generates ALL templates by running every command alphabetically",
}
// boilRun executes every sqlboiler command, starting with structs.
func boilRun(cmd *cobra.Command, args []string) {
// Exclude these commands from the output
skipTemplates := []string{
"boil",
}
var templateNames []string
// Build a list of template names
for _, c := range sqlBoilerCommands {
skip := false
for _, s := range skipTemplates {
// Skip name if it's in the exclude list.
// Also skip "struct" so that it can be added manually at the beginning
// of the slice. Structs should always go to the top of the file.
if s == c.Name() || c.Name() == "struct" {
skip = true
break
}
}
if !skip {
templateNames = append(templateNames, c.Name())
}
}
// Sort all names alphabetically
sort.Strings(templateNames)
// Prepend "struct" command to templateNames slice so it sits at top of sort
templateNames = append([]string{"struct"}, templateNames...)
// Loop through and generate every command template (excluding skipTemplates)
for _, n := range templateNames {
err := outHandler(generateTemplate(n))
if err != nil {
errorQuit(err)
}
}
}