-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
101 lines (82 loc) · 1.68 KB
/
utils.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
func ghqRoot() string {
out, err := exec.Command("ghq", "root").Output()
if err != nil {
log.Fatal(err)
}
return strings.Replace(string(out), "\n", "", -1)
}
func ghqPath() string {
out, err := exec.Command("ghq", "list").Output()
if err != nil {
log.Fatal(err)
}
return string(out)
}
func ghqList() []string {
out, err := exec.Command("ghq", "list").Output()
if err != nil {
log.Fatal(err)
}
repoNames := strings.Split(string(out), "\n")
return repoNames
}
func repoList(path string) []string {
dirs, err := ioutil.ReadDir(ghqRoot())
if err != nil {
log.Fatal(err)
}
var results []string
for _, dir := range dirs {
if dir.IsDir() {
results = append(results, dir.Name())
}
}
return results
}
func READMEContent(name string) string {
// TODO: READMEが含まれる文字列にしないとAsciiDocなどが表示されないので修正する
READMEPath := filepath.Join(ghqRoot(), name, "README.md")
f, err := os.Open(READMEPath)
if err != nil {
return "Not yet.."
}
defer f.Close()
text, err := ioutil.ReadAll(f)
if err != nil {
log.Fatal(err)
return string(text)
}
return string(text)
}
func cd(path string) {
err := exec.Command("cd", path).Run()
if err != nil {
log.Fatal(err)
}
}
func sandboxList(fullPath string) []string {
var fileList []string
files, err := filepath.Glob(filepath.Join(fullPath + "/*"))
if err != nil {
log.Fatal(err)
}
for _, file := range files {
info, err := os.Stat(file)
if err != nil {
log.Fatal(err)
}
if info.IsDir() && info.Name() != ".git" {
fileList = append(fileList, file)
}
}
return fileList
}