6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 20:19:42 +00:00
Files
git-get/pkg/list.go
2025-08-24 16:53:48 +02:00

48 lines
1004 B
Go

package pkg
import (
"errors"
"fmt"
"git-get/pkg/cfg"
"git-get/pkg/git"
"git-get/pkg/print"
"strings"
)
var ErrInvalidOutput = errors.New("invalid output format")
// 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("%w, allowed values: [%s]", ErrInvalidOutput, strings.Join(cfg.AllowedOut, ", "))
}
return nil
}