6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-05 01:29:42 +00:00
Files
git-get/pkg/print/flat.go
Grzegorz Dlugoszewski 32211e6408 Cleanup the print package
- Use strings.Builder instead of concatenation
- Move smart tree to a separate file
- Add missing docstrings
2020-06-18 19:20:03 +02:00

36 lines
963 B
Go

package print
import (
"fmt"
"git-get/pkg/repo"
"path/filepath"
"strings"
)
// FlatPrinter implements Printer interface and provides method for printing list of repos in flat format.
type FlatPrinter struct{}
// Print generates a flat list of repositories and their statuses - each repo in new line with full path.
func (p *FlatPrinter) Print(root string, repos []*repo.Repo) string {
var str strings.Builder
for _, r := range repos {
path := strings.TrimPrefix(r.Path, root)
path = strings.Trim(path, string(filepath.Separator))
str.WriteString(fmt.Sprintf("\n%s %s", path, printWorktreeStatus(r)))
for _, branch := range r.Status.Branches {
// Don't print the status of the current branch. It was already printed above.
if branch.Name == r.Status.CurrentBranch {
continue
}
indent := strings.Repeat(" ", len(path))
str.WriteString(fmt.Sprintf("\n%s %s", indent, printBranchStatus(branch)))
}
}
return str.String()
}