6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 19:44:41 +00:00
Files
git-get/pkg/list.go
2025-08-24 15:44:22 +02:00

45 lines
932 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(conf *ListCfg) error {
finder := git.NewRepoFinder(conf.Root)
if err := finder.Find(); err != nil {
return err
}
statuses := finder.LoadAll(conf.Fetch)
printables := make([]print.Printable, len(statuses))
for i := range statuses {
printables[i] = statuses[i]
}
switch conf.Output {
case cfg.OutFlat:
fmt.Print(print.NewFlatPrinter().Print(printables))
case cfg.OutTree:
fmt.Print(print.NewTreePrinter().Print(conf.Root, printables))
case cfg.OutDump:
fmt.Print(print.NewDumpPrinter().Print(printables))
default:
return fmt.Errorf("invalid --out flag; allowed values: [%s]", strings.Join(cfg.AllowedOut, ", "))
}
return nil
}