1
0
mirror of https://github.com/beego/bee.git synced 2024-12-22 15:10:49 +00:00

getting output from shell

This commit is contained in:
ZhengYang 2014-08-12 18:26:34 +08:00
parent 6f3d2d31ef
commit 5900befa43

View File

@ -197,12 +197,12 @@ func writeMigrationSourceFile(filename string, driver string, connStr string, la
}
func buildMigrationBinary(filename string) {
cmd := exec.Command("go", "build", "-o", filename, filename+".go")
os.Chdir(path.Join("database", "migrations"))
cmd := exec.Command("go", "build", "-o", filename)
if out, err := cmd.CombinedOutput(); err != nil {
ColorLog("[ERRO] Could not build migration binary: %s\n", err)
formatShellErrOutput(string(out))
os.Exit(2)
} else {
ColorLog("[INFO] %s\n", string(out))
}
}
@ -212,7 +212,7 @@ func runMigrationBinary(filename string) {
ColorLog("[ERRO] Could not run migration binary\n")
os.Exit(2)
} else {
ColorLog("[INFO] %s\n", string(out))
formatShellOutput(string(out))
}
}
@ -256,6 +256,22 @@ func migrate(goal, driver, connStr string) {
removeMigrationBinary(filepath)
}
func formatShellErrOutput(o string) {
for _, line := range strings.Split(o, "\n") {
if line != "" {
ColorLog("[ERRO] -| %s\n", line)
}
}
}
func formatShellOutput(o string) {
for _, line := range strings.Split(o, "\n") {
if line != "" {
ColorLog("[INFO] -| %s\n", line)
}
}
}
const (
MIGRATION_MAIN_TPL = `package main