Пример #1
0
func init() {
	flag.StringVar(&outfile, "o", "model_gen.go", "output file")
	flag.StringVar(&tmplfile, "t", Tmplfile, "template file, search current directory firstly, use default file $HOME/.config/go/"+Tmplfile+" if not found")
	flag.BoolVar(&copyTmpl, "cp", false, "copy tmpl file to default path")
	flag.BoolVar(&useAst, "ast", true, "parse sql ast")

	flag.BoolVar(&parseModel, "model", false, "generate model functions")
	flag.BoolVar(&parseSQL, "sql", false, "generate sqls")

	flag.Usage = func() {
		fmt.Println("gomodel [OPTIONS] DIR|FILES...")
		flag.PrintDefaults()
	}
	flag.Parse()

	if !file.IsExist(tmplfile) {
		tmplfile = defTmplPath
	}
}
Пример #2
0
// PackagePath find package absolute path use env variable GOPATH
func PackagePath(pkgName string) string {
	gopath := os.Getenv("GOPATH")
	if gopath == "" {
		return ""
	}

	fn := func(c rune) bool {
		sep := os.PathListSeparator

		return c == sep && sep != path2.UNKNOWN
	}
	for _, path := range strings.FieldsFunc(gopath, fn) {
		path = filepath.Join(path, "src", pkgName)

		if file.IsExist(path) && file.IsDir(path) {
			return path
		}
	}

	return ""
}