mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 17:24:49 +00:00
49 lines
995 B
Go
49 lines
995 B
Go
package pkg
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"git-get/pkg/cfg"
|
|
"git-get/pkg/git"
|
|
"git-get/pkg/out"
|
|
"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([]out.Printable, len(statuses))
|
|
|
|
for i := range statuses {
|
|
printables[i] = statuses[i]
|
|
}
|
|
|
|
switch conf.Output {
|
|
case cfg.OutFlat:
|
|
fmt.Print(out.NewFlatPrinter().Print(printables))
|
|
case cfg.OutTree:
|
|
fmt.Print(out.NewTreePrinter().Print(conf.Root, printables))
|
|
case cfg.OutDump:
|
|
fmt.Print(out.NewDumpPrinter().Print(printables))
|
|
default:
|
|
return fmt.Errorf("%w, allowed values: [%s]", ErrInvalidOutput, strings.Join(cfg.AllowedOut, ", "))
|
|
}
|
|
|
|
return nil
|
|
}
|