Refactor
This commit is contained in:
parent
74e7ef4451
commit
89955975bf
2 changed files with 36 additions and 28 deletions
33
internal/repositories/find.go
Normal file
33
internal/repositories/find.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package repositories
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
|
||||
"git-repo-updater/internal/utils"
|
||||
)
|
||||
|
||||
func FindInDirectory(dir string) (string, error) {
|
||||
expanded, err := utils.ExpandPath(dir)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
cmd := exec.Command("find", expanded, "-type", "d", "-name", ".git", "-mindepth", "1", "-maxdepth", "2")
|
||||
|
||||
output, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
exitCode := exitErr.ExitCode()
|
||||
|
||||
return "", fmt.Errorf("Command failed with exit code %d\n", exitCode)
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("find failed on %s: %w\nOutput: %s", dir, err, string(output))
|
||||
}
|
||||
|
||||
return string(output), nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue