github.com/gocaveman/caveman@v0.0.0-20191211162744-0ddf99dbdf6e/gen/demo-app-todo-sqlite3.go (about)

     1  package gen
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/spf13/pflag"
     7  )
     8  
     9  func init() {
    10  	globalMapGenerator["demo-app-todo-sqlite3"] = GeneratorFunc(func(s *Settings, name string, args ...string) error {
    11  
    12  		// generate our demo application by calling the other generators
    13  
    14  		fset := pflag.NewFlagSet("gen", pflag.ContinueOnError)
    15  		targetFile, _, err := ParsePFlagsAndOneFile(s, fset, args)
    16  		if err != nil {
    17  			return err
    18  		}
    19  
    20  		targetDir, _ := filepath.Split(targetFile)
    21  
    22  		// FIXME: We probably should generate this with whatever package structure
    23  		// we are going to recommend for projects, and it's probably not the
    24  		// "everything in main" approach.
    25  
    26  		err = globalMapGenerator.Generate(s, "main-rest-sqlite3", targetFile)
    27  		if err != nil {
    28  			return err
    29  		}
    30  		err = globalMapGenerator.Generate(s, "store", filepath.Join(targetDir, "store.go"))
    31  		if err != nil {
    32  			return err
    33  		}
    34  		err = globalMapGenerator.Generate(s, "model-sample-todo-list", filepath.Join(targetDir, "model-todo-list.go"))
    35  		if err != nil {
    36  			return err
    37  		}
    38  		err = globalMapGenerator.Generate(s, "store-crud", filepath.Join(targetDir, "store-todo-item.go"))
    39  		if err != nil {
    40  			return err
    41  		}
    42  		err = globalMapGenerator.Generate(s, "ctrl-api-crud", filepath.Join(targetDir, "ctrl-todo-item.go"))
    43  		if err != nil {
    44  			return err
    45  		}
    46  
    47  		return nil
    48  	})
    49  }