<commit_before>package main

import (
	"flag"
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"text/template"
)

var f1 = Field{
	FieldName: "id",
	FieldType: "bson.ObjectId",
	FieldAnn:  "",
}

//字段
type Field struct {
	FieldName string `json:"fName"`
	FieldType string `json:"fType"`
	FieldAnn  string `json:"anno,omitempty"`
	IsMust    bool   `json:"isMust"`
}

//方法
type Method struct {
	MethodName string  `json:"methodName"`
	Params     []Field `json:"params,omitempty"`
	ReturnType []Field `json:"returnType,omitempty"`
}

//模型
type Modle struct {
	Name        string   `json:"name"`
	PkgName     string   `json:"pkgName"`
	ProjectName string   `json:"ProjectName"`
	Fileds      []Field  `json:"fields"`
	Methods     []Method `json:"methods"`
	Annotation  string   `json:"annotation,omitempty"`
}

// ToUpper 大写
func ToUpper(content string) string {
	return strings.ToTitle(content)
}

func main() {

	// apigenerate -n "mc" [dir]

	name := flag.String("n", "", "models名字")
	pName := flag.String("p", "", "project/package名字")
	outPath := flag.String("d", ".", "输出路径")
	flag.Parse()
	modleName := *name
	if modleName == "" {
		fmt.Println("models not empty")
		os.Exit(1)
	}
	projectName := *pName
	if projectName == "" {
		fmt.Println("projectName not empty")
		os.Exit(1)
	}
	out := *outPath
	if out == "" || out == "." {
		out, _ = os.Getwd()
	}

	fmt.Printf("name:%s\noutpath:%s\n", modleName, out)
	var model Modle
	model.Name = modleName
	model.ProjectName = projectName
	model.PkgName = "models"
	model.Fileds = []Field{f1}

	currentPath := getCurrPath()
	fmt.Println("1:" + currentPath)
	currentPath = getParentDirectory(currentPath)
	fmt.Println("2:" + currentPath)
	tmplPath := filepath.Join(currentPath, "src", "github.com/shipizheng/apigenerate", "model.tpl")

	funcMap := template.FuncMap{
		"toLower": func(content string) string {
			return strings.ToLower(content)
		},
		"toTitle": func(content string) string {
			return strings.Title(content)
		},
	}

	tmpl := template.New("model.tpl")
	tmpl.Funcs(funcMap)
	tmpl = template.Must(tmpl.ParseFiles(tmplPath))
	// tmpl = tmpl.Funcs(funcMap)
	//
	fileNname := strings.ToLower(model.Name)<commit_msg>remove log<commit_after>package main

import (
	"flag"
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"text/template"
)

var f1 = Field{
	FieldName: "id",
	FieldType: "bson.ObjectId",
	FieldAnn:  "",
}

//字段
type Field struct {
	FieldName string `json:"fName"`
	FieldType string `json:"fType"`
	FieldAnn  string `json:"anno,omitempty"`
	IsMust    bool   `json:"isMust"`
}

//方法
type Method struct {
	MethodName string  `json:"methodName"`
	Params     []Field `json:"params,omitempty"`
	ReturnType []Field `json:"returnType,omitempty"`
}

//模型
type Modle struct {
	Name        string   `json:"name"`
	PkgName     string   `json:"pkgName"`
	ProjectName string   `json:"ProjectName"`
	Fileds      []Field  `json:"fields"`
	Methods     []Method `json:"methods"`
	Annotation  string   `json:"annotation,omitempty"`
}

// ToUpper 大写
func ToUpper(content string) string {
	return strings.ToTitle(content)
}

func main() {

	// apigenerate -n "mc" [dir]

	name := flag.String("n", "", "models名字")
	pName := flag.String("p", "", "project/package名字")
	outPath := flag.String("d", ".", "输出路径")
	flag.Parse()
	modleName := *name
	if modleName == "" {
		fmt.Println("models not empty")
		os.Exit(1)
	}
	projectName := *pName
	if projectName == "" {
		fmt.Println("projectName not empty")
		os.Exit(1)
	}
	out := *outPath
	if out == "" || out == "." {
		out, _ = os.Getwd()
	}

	fmt.Printf("name:%s\noutpath:%s\n", modleName, out)
	var model Modle
	model.Name = modleName
	model.ProjectName = projectName
	model.PkgName = "models"
	model.Fileds = []Field{f1}

	currentPath := getCurrPath()
	// fmt.Println("1:" + currentPath)
	currentPath = getParentDirectory(currentPath)
	// fmt.Println("2:" + currentPath)
	tmplPath := filepath.Join(currentPath, "src", "github.com/shipizheng/apigenerate", "model.tpl")

	funcMap := template.FuncMap{
		"toLower": func(content string) string {
			return strings.ToLower(content)
		},
		"toTitle": func(content string) string {
			return strings.Title(content)
		},
	}

	tmpl := template.New("model.tpl")
	tmpl.Funcs(funcMap)
	tmpl = template.Must(tmpl.ParseFiles(tmplPath))
	// tmpl = tmpl.Funcs(funcMap)
	//
	fileNname := strings.ToLower(model.Name)
{'fraction_non_alphanumeric': 0.17091660923501034, 'fraction_numerical': 0.0027567195037904893, 'mean_word_length': 4.12235294117647, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2661225', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1636, 'n_words': 332}