Skip to content

Commit

Permalink
Add format check to -typemap argument
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Jul 2, 2018
1 parent 5debbc6 commit 86dcce7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ func (tm TypeMap) Get(typeName string) *TypeMapEntry {
return nil
}

func (tm TypeMap) Check() error {
for idx, entry := range tm {
if entry.TypeName == "" {
return fmt.Errorf("entity #%d: typeName is not defined", idx+1)
}
if entry.EntityPath == "" {
return fmt.Errorf("entity #%d: entityPath is not defined", idx+1)
}
}
return nil
}

type TypeMapEntry struct {
TypeName string `yaml:"typeName"`
EntityPath string `yaml:"entityPath"`
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func main() {
}

types := loadTypeMap()
err = types.Check()
if err != nil {
fmt.Fprintln(os.Stderr, "invalid typemap format: "+err.Error())
os.Exit(1)
}

err = codegen.Generate(codegen.Config{
ModelFilename: *models,
Expand Down

0 comments on commit 86dcce7

Please sign in to comment.