mirror of
https://github.com/cheat/cheat.git
synced 2024-11-23 22:41:35 +01:00
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:
parent
80c91cbdee
commit
a2f538f114
@ -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)
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package installer
|
||||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -7,11 +7,11 @@ import (
|
||||
"github.com/go-git/go-git/v5"
|
||||
)
|
||||
|
||||
// clone clones the community cheatsheets
|
||||
func clone(path string) error {
|
||||
// Clone clones the repo available at `url`
|
||||
func Clone(url string) error {
|
||||
|
||||
// clone the community cheatsheets
|
||||
_, err := git.PlainClone(path, false, &git.CloneOptions{
|
||||
_, err := git.PlainClone(url, false, &git.CloneOptions{
|
||||
URL: "https://github.com/cheat/cheatsheets.git",
|
||||
Depth: 1,
|
||||
Progress: os.Stdout,
|
@ -1,4 +1,4 @@
|
||||
package sheets
|
||||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -6,9 +6,9 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// isGitDir returns `true` if `path` is within a `.git` directory, or `false`
|
||||
// otherwise
|
||||
func isGitDir(path string) (bool, error) {
|
||||
// GitDir returns `true` if we are iterating over a directory contained within
|
||||
// a repositories `.git` directory.
|
||||
func GitDir(path string) (bool, error) {
|
||||
|
||||
/*
|
||||
A bit of context is called for here, because this functionality has
|
1
internal/repo/update.go
Normal file
1
internal/repo/update.go
Normal file
@ -0,0 +1 @@
|
||||
package repo
|
@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
cp "github.com/cheat/cheat/internal/cheatpath"
|
||||
"github.com/cheat/cheat/internal/repo"
|
||||
"github.com/cheat/cheat/internal/sheet"
|
||||
)
|
||||
|
||||
@ -52,7 +53,7 @@ func Load(cheatpaths []cp.Cheatpath) ([]map[string]sheet.Sheet, error) {
|
||||
// Don't walk the `.git` directory. Doing so creates
|
||||
// hundreds/thousands of needless syscalls and could
|
||||
// potentially harm performance on machines with slow disks.
|
||||
skip, err := isGitDir(path)
|
||||
skip, err := repo.GitDir(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to identify .git directory: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user