github.com/ppphp/yayagf@v0.0.1/cmd/generate/schema/schema.go (about)

     1  package schema
     2  
     3  import (
     4  	"log"
     5  	"path/filepath"
     6  	"strings"
     7  
     8  	"github.com/ppphp/yayagf/internal/ent"
     9  
    10  	"github.com/ppphp/yayagf/internal/file"
    11  	"github.com/ppphp/yayagf/pkg/cli"
    12  )
    13  
    14  func CommandFactory() (*cli.Command, error) {
    15  	c := &cli.Command{
    16  		Run: func(args []string, flags map[string]string) (int, error) {
    17  			root, err := file.GetAppRoot()
    18  			if err != nil {
    19  				log.Printf("get project name failed: %v", err.Error())
    20  				return 1, err
    21  			}
    22  			schemas := []string{}
    23  			for _, a := range args {
    24  				schemas = append(schemas, strings.Title(a))
    25  			}
    26  			if err := ent.GenerateSchema(filepath.Join(root, "app", "schema"), schemas); err != nil {
    27  				return 1, err
    28  			}
    29  
    30  			return 0, nil
    31  		},
    32  	}
    33  	return c, nil
    34  }