mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 15:39:46 +00:00
- Simplify the main functions by moving actual implementation to "pkg" package - Remove the "path" package and move files into the root "pkg" package - Replace viper with explicit Cfg structs
59 lines
884 B
Go
59 lines
884 B
Go
package pkg
|
|
|
|
import (
|
|
"git-get/pkg/repo"
|
|
"path"
|
|
)
|
|
|
|
// GetCfg provides configuration for the Get command.
|
|
type GetCfg struct {
|
|
Branch string
|
|
Dump string
|
|
Root string
|
|
URL string
|
|
}
|
|
|
|
// Get executes the "git get" command.
|
|
func Get(c *GetCfg) error {
|
|
if c.Dump != "" {
|
|
return cloneDumpFile(c)
|
|
}
|
|
|
|
if c.URL != "" {
|
|
return cloneSingleRepo(c)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func cloneSingleRepo(c *GetCfg) error {
|
|
url, err := ParseURL(c.URL)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
cloneOpts := &repo.CloneOpts{
|
|
URL: url,
|
|
Path: path.Join(c.Root, URLToPath(url)),
|
|
Branch: c.Branch,
|
|
}
|
|
|
|
_, err = repo.Clone(cloneOpts)
|
|
|
|
return err
|
|
}
|
|
|
|
func cloneDumpFile(c *GetCfg) error {
|
|
opts, err := ParseBundleFile(c.Dump)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, opt := range opts {
|
|
path := path.Join(c.Root, URLToPath(opt.URL))
|
|
opt.Path = path
|
|
_, _ = repo.Clone(opt)
|
|
}
|
|
return nil
|
|
}
|