Changed cmddata receiver names to single letter

This commit is contained in:
Patrick O'brien 2016-04-03 16:21:45 +10:00
parent f76022c1f6
commit a7263bde40
2 changed files with 22 additions and 22 deletions

View file

@ -91,7 +91,7 @@ var sqlBoilerTemplateFuncs = template.FuncMap{
} }
// LoadConfigFile loads the toml config file into the cfg object // LoadConfigFile loads the toml config file into the cfg object
func (cmdData *CmdData) LoadConfigFile(filename string) error { func (c *CmdData) LoadConfigFile(filename string) error {
cfg := &Config{} cfg := &Config{}
_, err := toml.DecodeFile(filename, &cfg) _, err := toml.DecodeFile(filename, &cfg)

View file

@ -18,14 +18,14 @@ const (
) )
// LoadTemplates loads all template folders into the cmdData object. // LoadTemplates loads all template folders into the cmdData object.
func (cmdData *CmdData) LoadTemplates() error { func (c *CmdData) LoadTemplates() error {
var err error var err error
cmdData.Templates, err = loadTemplates(templatesDirectory) c.Templates, err = loadTemplates(templatesDirectory)
if err != nil { if err != nil {
return err return err
} }
cmdData.TestTemplates, err = loadTemplates(templatesTestDirectory) c.TestTemplates, err = loadTemplates(templatesTestDirectory)
if err != nil { if err != nil {
return err return err
} }
@ -51,13 +51,13 @@ func loadTemplates(dir string) ([]*template.Template, error) {
} }
// SQLBoilerPostRun cleans up the output file and db connection once all cmds are finished. // SQLBoilerPostRun cleans up the output file and db connection once all cmds are finished.
func (cmdData *CmdData) SQLBoilerPostRun(cmd *cobra.Command, args []string) error { func (c *CmdData) SQLBoilerPostRun(cmd *cobra.Command, args []string) error {
cmdData.Interface.Close() c.Interface.Close()
return nil return nil
} }
// SQLBoilerPreRun performs the initialization tasks before the root command is run // SQLBoilerPreRun performs the initialization tasks before the root command is run
func (cmdData *CmdData) SQLBoilerPreRun(cmd *cobra.Command, args []string) error { func (c *CmdData) SQLBoilerPreRun(cmd *cobra.Command, args []string) error {
// Initialize package name // Initialize package name
pkgName := cmd.PersistentFlags().Lookup("pkgname").Value.String() pkgName := cmd.PersistentFlags().Lookup("pkgname").Value.String()
@ -74,30 +74,30 @@ func (cmdData *CmdData) SQLBoilerPreRun(cmd *cobra.Command, args []string) error
return fmt.Errorf("No output folder specified.") return fmt.Errorf("No output folder specified.")
} }
return cmdData.initCmdData(pkgName, driverName, tableName, outFolder) return c.initCmdData(pkgName, driverName, tableName, outFolder)
} }
// SQLBoilerRun is a proxy method for the run function // SQLBoilerRun is a proxy method for the run function
func (cmdData *CmdData) SQLBoilerRun(cmd *cobra.Command, args []string) error { func (c *CmdData) SQLBoilerRun(cmd *cobra.Command, args []string) error {
return cmdData.run(true) return c.run(true)
} }
// run executes the sqlboiler templates and outputs them to files. // run executes the sqlboiler templates and outputs them to files.
func (cmdData *CmdData) run(includeTests bool) error { func (c *CmdData) run(includeTests bool) error {
for _, table := range cmdData.Tables { for _, table := range c.Tables {
data := &tplData{ data := &tplData{
Table: table, Table: table,
PkgName: cmdData.PkgName, PkgName: c.PkgName,
} }
// Generate the regular templates // Generate the regular templates
if err := generateOutput(cmdData, data, false); err != nil { if err := generateOutput(c, data, false); err != nil {
return fmt.Errorf("Unable to generate test output: %s", err) return fmt.Errorf("Unable to generate test output: %s", err)
} }
// Generate the test templates // Generate the test templates
if includeTests { if includeTests {
if err := generateOutput(cmdData, data, true); err != nil { if err := generateOutput(c, data, true); err != nil {
return fmt.Errorf("Unable to generate output: %s", err) return fmt.Errorf("Unable to generate output: %s", err)
} }
} }
@ -106,26 +106,26 @@ func (cmdData *CmdData) run(includeTests bool) error {
return nil return nil
} }
func (cmdData *CmdData) initCmdData(pkgName, driverName, tableName, outFolder string) error { func (c *CmdData) initCmdData(pkgName, driverName, tableName, outFolder string) error {
cmdData.OutFolder = outFolder c.OutFolder = outFolder
cmdData.PkgName = pkgName c.PkgName = pkgName
err := initInterface(driverName, cmdData) err := initInterface(driverName, c)
if err != nil { if err != nil {
return err return err
} }
// Connect to the driver database // Connect to the driver database
if err = cmdData.Interface.Open(); err != nil { if err = c.Interface.Open(); err != nil {
return fmt.Errorf("Unable to connect to the database: %s", err) return fmt.Errorf("Unable to connect to the database: %s", err)
} }
err = initTables(tableName, cmdData) err = initTables(tableName, c)
if err != nil { if err != nil {
return fmt.Errorf("Unable to initialize tables: %s", err) return fmt.Errorf("Unable to initialize tables: %s", err)
} }
err = initOutFolder(cmdData) err = initOutFolder(c)
if err != nil { if err != nil {
return fmt.Errorf("Unable to initialize the output folder: %s", err) return fmt.Errorf("Unable to initialize the output folder: %s", err)
} }