func main() { args := flag.Args() path := "." if len(args) != 0 { path = args[0] } ext = "." + ext wg := sync.WaitGroup{} errors.Fatal( filepath.Walk(path, func(path string, info os.FileInfo, err error) error { if err != nil { return err } if !info.IsDir() && filepath.Ext(info.Name()) == ext { wg.Add(1) go process(path, &wg) } return nil }), ) wg.Wait() errors.CondDo(len(as.categories) == 0, errors.Err("No files contains api in this dir or file"), errors.FatalAnyln) errors.CondDo(outputType != "md", errors.Err("Sorry, currently only support markdown format"), errors.FatalAnyln) orders := slices.Strings(strings2.SplitAndTrim(order, orderSep)).Clear("") if fname != "" { errors.Fatalln(file.OpenOrCreate(fname, overwrite, func(fd *os.File) error { as.WriteMarkDown(fd, orders) return nil })) } else { as.WriteMarkDown(os.Stdout, orders) } }
func main() { if copyTmpl { errors.Fatal(file.Copy(defTmplPath, Tmplfile)) return } args := flag.Args() if len(args) == 0 { flag.Usage() return } if !parseSQL && !parseModel { fmt.Println("neighter -model nor -sql are specified.") return } v := newVisitor() if len(args) == 1 { errors.Fatalln(v.parseDir(args[0])) } else { errors.Fatalln(v.parseFiles(args...)) } if len(v.Models) == 0 { fmt.Println("no models found.") return } var result struct { Models map[*Model][]*Field SQLs map[string]string } if parseSQL { var err error for name, sql := range v.SQLs { if useAst { sql, err = v.astConv(sql) } else { sql, err = v.conv(sql) } if err != nil { color.Red.Errorf("%s: %s\n", name, err) } else { v.SQLs[name] = sql } } result.SQLs = v.SQLs } if parseModel { result.Models = v.buildModelFields() } errors.Fatal( file.OpenOrCreate(outfile, false, func(fd *os.File) error { t, err := template.ParseFiles(tmplfile) if err != nil { return err } return t.Execute(fd, result) }), ) }