6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 15:39:46 +00:00
Files
git-get/pkg/list.go
Grzegorz Dlugoszewski 3aef50a4d0 Move status loader into the git package
- Loading status belongs to git domain so it makes more sense for it to
  be in git package.
- It also makes the `list` file simpler.
- Because status loader is now part of the RepoFinder, the ugly Repo interface is no longer necessary.
2020-07-27 11:15:35 +02:00

44 lines
922 B
Go

package pkg
import (
"fmt"
"git-get/pkg/cfg"
"git-get/pkg/git"
"git-get/pkg/print"
"strings"
)
// ListCfg provides configuration for the List command.
type ListCfg struct {
Fetch bool
Output string
Root string
}
// List executes the "git list" command.
func List(c *ListCfg) error {
finder := git.NewRepoFinder(c.Root)
if err := finder.Find(); err != nil {
return err
}
statuses := finder.LoadAll(c.Fetch)
printables := make([]print.Printable, len(statuses))
for i := range statuses {
printables[i] = statuses[i]
}
switch c.Output {
case cfg.OutFlat:
fmt.Println(print.NewFlatPrinter().Print(printables))
case cfg.OutTree:
fmt.Println(print.NewTreePrinter().Print(c.Root, printables))
case cfg.OutDump:
fmt.Println(print.NewDumpPrinter().Print(printables))
default:
return fmt.Errorf("invalid --out flag; allowed values: [%s]", strings.Join(cfg.AllowedOut, ", "))
}
return nil
}