6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-10 12:34:23 +00:00

Indicate if error occured during status loading and print the list of errors

This commit is contained in:
Grzegorz Dlugoszewski
2020-07-27 16:17:13 +02:00
parent d660a73c7f
commit b2d1d773f7
7 changed files with 107 additions and 59 deletions

View File

@@ -1,6 +1,9 @@
package print
import "fmt"
import (
"fmt"
"strings"
)
const (
head = "HEAD"
@@ -17,6 +20,28 @@ type Printable interface {
Errors() []string
}
// Errors returns a printable list of errors from the slice of Printables or an empty string if there are no errors.
// It's meant to be appended at the end of Print() result.
func Errors(repos []Printable) string {
errors := []string{}
for _, repo := range repos {
for _, err := range repo.Errors() {
errors = append(errors, err)
}
}
if len(errors) == 0 {
return ""
}
var str strings.Builder
str.WriteString(red("\nOops, errors happened when loading repository status:\n"))
str.WriteString(strings.Join(errors, "\n"))
return str.String()
}
// TODO: not sure if this works on windows. See https://github.com/mattn/go-colorable
func red(str string) string {
return fmt.Sprintf("\033[1;31m%s\033[0m", str)