Example #1
0
// WriteString write string to writer
func (m WriteMode) WriteString(fname, str string) (c int, err error) {
	err = file.OpenOrCreate(fname, bool(m), func(fd *os.File) error {
		c, err = fd.Write(unsafe2.Bytes(str))

		return err
	})

	return
}
Example #2
0
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)
	}
}
Example #3
0
func (m WriteMode) WriteGZIP(fname string, v interface{}) (err error) {
	return file.OpenOrCreate(fname, bool(m), func(fd *os.File) error {
		return encodeio.WriteGZIP(fd, v)
	})
}
Example #4
0
func (m WriteMode) Write(fname string, v interface{}, encoder encodeio.EncodeFunc) error {
	return file.OpenOrCreate(fname, bool(m), func(fd *os.File) error {
		return encodeio.Write(fd, v, encoder)
	})
}
Example #5
0
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)
		}),
	)
}
Example #6
0
// WriteXML write interface{} to writer use xml encoder
func (m WriteMode) WriteXML(fname string, v interface{}) error {
	return file.OpenOrCreate(fname, bool(m), func(fd *os.File) error {
		return encoding2.WriteXML(fd, v)
	})
}