Add json tables output to debug mode

This commit is contained in:
Patrick O'brien 2016-09-04 20:27:19 +10:00
parent 513e490c00
commit e35ecd76c1
3 changed files with 15 additions and 1 deletions

View file

@ -7,6 +7,7 @@ type Config struct {
OutFolder string OutFolder string
BaseDir string BaseDir string
ExcludeTables []string ExcludeTables []string
Debug bool
NoTests bool NoTests bool
NoHooks bool NoHooks bool
NoAutoTimestamps bool NoAutoTimestamps bool

View file

@ -78,7 +78,7 @@ func main() {
if e, ok := err.(commandFailure); ok { if e, ok := err.(commandFailure); ok {
fmt.Printf("Error: %v\n\n", string(e)) fmt.Printf("Error: %v\n\n", string(e))
rootCmd.Help() rootCmd.Help()
} else if !viper.GetBool("debug") { } else if !cmdConfig.Debug {
fmt.Printf("Error: %v\n", err) fmt.Printf("Error: %v\n", err)
} else { } else {
fmt.Printf("Error: %+v\n", err) fmt.Printf("Error: %+v\n", err)
@ -107,6 +107,7 @@ func preRun(cmd *cobra.Command, args []string) error {
DriverName: driverName, DriverName: driverName,
OutFolder: viper.GetString("output"), OutFolder: viper.GetString("output"),
PkgName: viper.GetString("pkgname"), PkgName: viper.GetString("pkgname"),
Debug: viper.GetBool("debug"),
NoTests: viper.GetBool("no-tests"), NoTests: viper.GetBool("no-tests"),
NoHooks: viper.GetBool("no-hooks"), NoHooks: viper.GetBool("no-hooks"),
NoAutoTimestamps: viper.GetBool("no-auto-timestamps"), NoAutoTimestamps: viper.GetBool("no-auto-timestamps"),

View file

@ -3,6 +3,8 @@
package main package main
import ( import (
"encoding/json"
"fmt"
"go/build" "go/build"
"os" "os"
"path/filepath" "path/filepath"
@ -12,6 +14,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/vattle/sqlboiler/bdb" "github.com/vattle/sqlboiler/bdb"
"github.com/vattle/sqlboiler/bdb/drivers" "github.com/vattle/sqlboiler/bdb/drivers"
"github.com/vattle/sqlboiler/boil"
) )
const ( const (
@ -60,6 +63,15 @@ func New(config *Config) (*State, error) {
return nil, errors.Wrap(err, "unable to initialize tables") return nil, errors.Wrap(err, "unable to initialize tables")
} }
if s.Config.Debug {
b, err := json.Marshal(s.Tables)
if err != nil {
return nil, errors.Wrap(err, "unable to json marshal tables")
}
boil.DebugWriter.Write(b)
fmt.Fprintln(boil.DebugWriter)
}
err = s.initOutFolder() err = s.initOutFolder()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "unable to initialize the output folder") return nil, errors.Wrap(err, "unable to initialize the output folder")