6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-08 15:09:19 +00:00

Add output flag and simple tree option

This commit is contained in:
Grzegorz Dlugoszewski
2020-06-08 14:00:59 +02:00
parent f3d0df1bfd
commit e5c3285040
8 changed files with 123 additions and 54 deletions

33
print/flat.go Normal file
View File

@@ -0,0 +1,33 @@
package print
import (
"fmt"
"git-get/git"
"path/filepath"
"strings"
)
type FlatPrinter struct{}
func (p *FlatPrinter) Print(root string, repos []*git.Repo) string {
val := root
for _, repo := range repos {
path := strings.TrimPrefix(repo.Path, root)
path = strings.Trim(path, string(filepath.Separator))
val += fmt.Sprintf("\n%s %s", path, printWorktreeStatus(repo))
for _, branch := range repo.Status.Branches {
// Don't print the status of the current branch. It was already printed above.
if branch.Name == repo.Status.CurrentBranch {
continue
}
indent := strings.Repeat(" ", len(path))
val += fmt.Sprintf("\n%s %s", indent, printBranchStatus(branch))
}
}
return val
}