From 5900befa43ca35c7225b3bf0e3131e46a70d282d Mon Sep 17 00:00:00 2001 From: ZhengYang Date: Tue, 12 Aug 2014 18:26:34 +0800 Subject: [PATCH] getting output from shell --- migrate.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/migrate.go b/migrate.go index fef2474..3b83ced 100644 --- a/migrate.go +++ b/migrate.go @@ -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