Просмотр исходного кода

CLI: Use console logger for dashbard:import command

More consistent w/ other commands and separates stdout/stderr
Jason Wilder 11 лет назад
Родитель
Сommit
a3925e8aa0
1 измененных файлов с 7 добавлено и 11 удалено
  1. 7 11
      pkg/cmd/dashboard.go

+ 7 - 11
pkg/cmd/dashboard.go

@@ -30,19 +30,16 @@ var ImportJson = cli.Command{
 func runImport(c *cli.Context) {
 	dir := c.String("dir")
 	if len(dir) == 0 {
-		log.Error(3, "Missing command flag --dir")
-		return
+		log.ConsoleFatalf("Missing command flag --dir")
 	}
 
 	file, err := os.Stat(dir)
 	if os.IsNotExist(err) {
-		log.Error(3, "Directory does not exist: %v", dir)
-		return
+		log.ConsoleFatalf("Directory does not exist: %v", dir)
 	}
 
 	if !file.IsDir() {
-		log.Error(3, "%v is not a directory", dir)
-		return
+		log.ConsoleFatalf("%v is not a directory", dir)
 	}
 
 	if !c.Args().Present() {
@@ -57,8 +54,7 @@ func runImport(c *cli.Context) {
 
 	accountQuery := m.GetAccountByNameQuery{Name: accountName}
 	if err := bus.Dispatch(&accountQuery); err != nil {
-		log.Error(3, "Failed to find account", err)
-		return
+		log.ConsoleFatalf("Failed to find account", err)
 	}
 
 	accountId := accountQuery.Result.Id
@@ -72,19 +68,19 @@ func runImport(c *cli.Context) {
 		}
 		if strings.HasSuffix(f.Name(), ".json") {
 			if err := importDashboard(path, accountId); err != nil {
-				log.Error(3, "Failed to import dashboard file: %v,  err: %v", path, err)
+				log.ConsoleFatalf("Failed to import dashboard file: %v,  err: %v", path, err)
 			}
 		}
 		return nil
 	}
 
 	if err := filepath.Walk(dir, visitor); err != nil {
-		log.Error(3, "failed to scan dir for json files: %v", err)
+		log.ConsoleFatalf("Failed to scan dir for json files: %v", err)
 	}
 }
 
 func importDashboard(path string, accountId int64) error {
-	log.Info("Importing %v", path)
+	log.ConsoleInfof("Importing %v", path)
 
 	reader, err := os.Open(path)
 	if err != nil {