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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user