From 86dcce730bad2f06b48faf7f8ea1f27af668de50 Mon Sep 17 00:00:00 2001 From: vvakame Date: Mon, 2 Jul 2018 19:21:17 +0900 Subject: [PATCH] Add format check to -typemap argument --- codegen/codegen.go | 12 ++++++++++++ main.go | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/codegen/codegen.go b/codegen/codegen.go index 25989b8d3f7..df5d6e21a9e 100644 --- a/codegen/codegen.go +++ b/codegen/codegen.go @@ -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"` diff --git a/main.go b/main.go index 44cd3a08887..f4d49055ee7 100644 --- a/main.go +++ b/main.go @@ -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,