mirror of https://github.com/cheat/cheat.git
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"
|
"strings"
|
||||||
|
|
||||||
"github.com/cheat/cheat/internal/config"
|
"github.com/cheat/cheat/internal/config"
|
||||||
|
"github.com/cheat/cheat/internal/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Run runs the installer
|
// Run runs the installer
|
||||||
|
@ -45,7 +46,7 @@ func Run(configs string, confpath string) error {
|
||||||
if yes {
|
if yes {
|
||||||
// clone the community cheatsheets
|
// clone the community cheatsheets
|
||||||
fmt.Printf("Cloning community cheatsheets to %s.\n", community)
|
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)
|
return fmt.Errorf("failed to clone cheatsheets: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package installer
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -7,11 +7,11 @@ import (
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
// clone clones the community cheatsheets
|
// Clone clones the repo available at `url`
|
||||||
func clone(path string) error {
|
func Clone(url string) error {
|
||||||
|
|
||||||
// clone the community cheatsheets
|
// 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",
|
URL: "https://github.com/cheat/cheatsheets.git",
|
||||||
Depth: 1,
|
Depth: 1,
|
||||||
Progress: os.Stdout,
|
Progress: os.Stdout,
|
|
@ -1,4 +1,4 @@
|
||||||
package sheets
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -6,9 +6,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// isGitDir returns `true` if `path` is within a `.git` directory, or `false`
|
// GitDir returns `true` if we are iterating over a directory contained within
|
||||||
// otherwise
|
// a repositories `.git` directory.
|
||||||
func isGitDir(path string) (bool, error) {
|
func GitDir(path string) (bool, error) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
A bit of context is called for here, because this functionality has
|
A bit of context is called for here, because this functionality has
|
|
@ -0,0 +1 @@
|
||||||
|
package repo
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
cp "github.com/cheat/cheat/internal/cheatpath"
|
cp "github.com/cheat/cheat/internal/cheatpath"
|
||||||
|
"github.com/cheat/cheat/internal/repo"
|
||||||
"github.com/cheat/cheat/internal/sheet"
|
"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
|
// Don't walk the `.git` directory. Doing so creates
|
||||||
// hundreds/thousands of needless syscalls and could
|
// hundreds/thousands of needless syscalls and could
|
||||||
// potentially harm performance on machines with slow disks.
|
// potentially harm performance on machines with slow disks.
|
||||||
skip, err := isGitDir(path)
|
skip, err := repo.GitDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to identify .git directory: %v", err)
|
return fmt.Errorf("failed to identify .git directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue