refactor(repo): create repo package

- Refactor `installer.clone` into new `repo.Clone` package and method.

- Refactor `sheets.isGitDir` into `repo.GitDir`.

Both of these changes read better, and will facilitate cleaner
architecture when `--update` is implemented.
This commit is contained in:
Christopher Allen Lane
2022-08-26 19:20:24 -04:00
parent 80c91cbdee
commit a2f538f114
5 changed files with 13 additions and 10 deletions

View File

@ -1,25 +0,0 @@
package installer
import (
"fmt"
"os"
"github.com/go-git/go-git/v5"
)
// clone clones the community cheatsheets
func clone(path string) error {
// clone the community cheatsheets
_, err := git.PlainClone(path, false, &git.CloneOptions{
URL: "https://github.com/cheat/cheatsheets.git",
Depth: 1,
Progress: os.Stdout,
})
if err != nil {
return fmt.Errorf("failed to clone cheatsheets: %v", err)
}
return nil
}

View File

@ -7,6 +7,7 @@ import (
"strings"
"github.com/cheat/cheat/internal/config"
"github.com/cheat/cheat/internal/repo"
)
// Run runs the installer
@ -45,7 +46,7 @@ func Run(configs string, confpath string) error {
if yes {
// clone the community cheatsheets
fmt.Printf("Cloning community cheatsheets to %s.\n", community)
if err := clone(community); err != nil {
if err := repo.Clone(community); err != nil {
return fmt.Errorf("failed to clone cheatsheets: %v", err)
}