go-zero/tools/goctl/api/dartgen/format.go
Fyn 6a66dde0a1
feat(goctl): api dart support flutter v2 (#1603)
0. support null-safety code gen
1. supports -legacy flag for legacy code gen
2. supports -hostname flag for server hostname
3. use dart official format
4. fix some some bugs

Resolves: #1602
2022-03-04 15:34:13 +08:00

41 lines
626 B
Go

package dartgen
import (
"fmt"
"os"
"os/exec"
)
const dartExec = "dart"
func formatDir(dir string) error {
ok, err := dirctoryExists(dir)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("format failed, directory %q does not exist", dir)
}
_, err = exec.LookPath(dartExec)
if err != nil {
return err
}
cmd := exec.Command(dartExec, "format", dir)
cmd.Env = os.Environ()
cmd.Stderr = os.Stderr
return cmd.Run()
}
func dirctoryExists(dir string) (bool, error) {
_, err := os.Stat(dir)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}