mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
6a66dde0a1
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
41 lines
626 B
Go
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
|
|
}
|