-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.go
41 lines (34 loc) · 878 Bytes
/
select.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"os"
"path/filepath"
)
func selectRepo(repoBasePath string) string {
log := NewLogUtil()
repos, err := getRepos(repoBasePath)
if err != nil {
log.Negative("Error getting repositories: %s", err)
os.Exit(1)
}
return fzf(repos, "Select repository: ")
}
func getRepos(repoBasePath string) ([]string, error) {
usernames, err := readDirs(repoBasePath)
if err != nil {
return nil, fmt.Errorf("reading username directory: %w", err)
}
var repos []string
for _, username := range usernames {
repoPath := filepath.Join(repoBasePath, username)
reposInUser, err := readDirs(repoPath)
if err != nil {
return nil, fmt.Errorf("reading repo directory for '%s': %w", username, err)
}
for _, repo := range reposInUser {
repoEntry := filepath.Join(username, repo)
repos = append(repos, repoEntry)
}
}
return repos, nil
}