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
BaseDir string
ExcludeTables []string
Debug bool
NoTests bool
NoHooks bool
NoAutoTimestamps bool

View file

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

View file

@ -3,6 +3,8 @@
package main
import (
"encoding/json"
"fmt"
"go/build"
"os"
"path/filepath"
@ -12,6 +14,7 @@ import (
"github.com/pkg/errors"
"github.com/vattle/sqlboiler/bdb"
"github.com/vattle/sqlboiler/bdb/drivers"
"github.com/vattle/sqlboiler/boil"
)
const (
@ -60,6 +63,15 @@ func New(config *Config) (*State, error) {
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()
if err != nil {
return nil, errors.Wrap(err, "unable to initialize the output folder")