Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: tbls out -t config does not set default values #170

Merged
merged 2 commits into from
Feb 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func withDot(s *schema.Schema, c *config.Config, force bool) (e error) {
erFileName := fmt.Sprintf("schema.%s", erFormat)
fmt.Printf("%s\n", filepath.Join(outputPath, erFileName))

file, err := os.OpenFile(filepath.Join(fullPath, erFileName), os.O_WRONLY|os.O_CREATE, 0644)
file, err := os.OpenFile(filepath.Join(fullPath, erFileName), os.O_WRONLY|os.O_CREATE, 0644) // #nosec
if err != nil {
return errors.WithStack(err)
}
Expand All @@ -130,7 +130,7 @@ func withDot(s *schema.Schema, c *config.Config, force bool) (e error) {
erFileName := fmt.Sprintf("%s.%s", t.Name, erFormat)
fmt.Printf("%s\n", filepath.Join(outputPath, erFileName))

file, err := os.OpenFile(filepath.Join(fullPath, erFileName), os.O_WRONLY|os.O_CREATE, 0644)
file, err := os.OpenFile(filepath.Join(fullPath, erFileName), os.O_WRONLY|os.O_CREATE, 0644) // #nosec
if err != nil {
return errors.WithStack(err)
}
Expand Down
10 changes: 10 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ func (c *Config) Load(configPath string, options ...Option) error {
}
}

err = c.SetDefault()
if err != nil {
return err
}

return nil
}

// SetDefault set default setting
func (c *Config) SetDefault() error {
if c.DocPath == "" {
c.DocPath = defaultDocPath
}
Expand Down
7 changes: 5 additions & 2 deletions output/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ func (c *Config) OutputSchema(wr io.Writer, s *schema.Schema) error {
}
}

if err := c.config.SetDefault(); err != nil {
return errors.WithStack(err)
}

d := yaml.NewEncoder(wr)
defer d.Close()
err := d.Encode(c.config)
if err != nil {
if err := d.Encode(c.config); err != nil {
return errors.WithStack(err)
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions testdata/config_test.yml.golden
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
dsn: ""
docPath: ""
docPath: dbdoc
format:
adjust: false
sort: false
er:
skip: false
format: ""
format: png
comment: false
exclude: []
lint:
Expand Down