Skip to content

Commit 6392688

Browse files
committed
fix: Fix generate for add force write options
1 parent ad99753 commit 6392688

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

internal/actions/generate.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,17 @@ func (a *GenerateAction) RunWithConfig(ctx context.Context, cfgName string) erro
5454
if err := utils.ParseJSONFile(name, &data); err != nil {
5555
return err
5656
}
57-
return a.run(ctx, data)
5857
case ".yaml", "yml":
5958
if err := utils.ParseYAMLFile(name, &data); err != nil {
6059
return err
6160
}
62-
return a.run(ctx, data)
6361
default:
6462
a.logger.Warnf("Ignore file %s, only support json/yaml/yml", name)
6563
}
66-
return nil
64+
if len(data) == 0 {
65+
return nil
66+
}
67+
return a.run(ctx, data)
6768
}
6869

6970
if utils.IsDir(cfgName) {
@@ -227,7 +228,7 @@ func (a *GenerateAction) generate(ctx context.Context, dataItem *schema.S) error
227228
return err
228229
}
229230

230-
err = a.write(ctx, dataItem.ModuleName, dataItem.Name, parser.StructPackageTplPaths[pkgName], tplData, true)
231+
err = a.write(ctx, dataItem.ModuleName, dataItem.Name, parser.StructPackageTplPaths[pkgName], tplData, !dataItem.ForceWrite)
231232
if err != nil {
232233
return err
233234
}

internal/schema/struct.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type S struct {
2323
TableName string `yaml:"table_name,omitempty" json:"table_name,omitempty"`
2424
Comment string `yaml:"comment,omitempty" json:"comment,omitempty"`
2525
Outputs []string `yaml:"outputs,omitempty" json:"outputs,omitempty"`
26+
ForceWrite bool `yaml:"force_write,omitempty" json:"force_write,omitempty"`
2627
TplType string `yaml:"tpl_type,omitempty" json:"tpl_type,omitempty"` // crud/tree
2728
DisablePagination bool `yaml:"disable_pagination,omitempty" json:"disable_pagination,omitempty"`
2829
DisableDefaultFields bool `yaml:"disable_default_fields,omitempty" json:"disable_default_fields,omitempty"`

0 commit comments

Comments
 (0)