forked from gabrie30/ghorg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathls.go
More file actions
65 lines (52 loc) · 1.29 KB
/
ls.go
File metadata and controls
65 lines (52 loc) · 1.29 KB
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
package cmd
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"github.com/gabrie30/ghorg/colorlog"
"github.com/gabrie30/ghorg/configs"
"github.com/spf13/cobra"
)
var lsCmd = &cobra.Command{
Use: "ls [dir]",
Short: "List contents of your ghorg home or ghorg directories",
Long: `If no dir is specified it will list contents of GHORG_ABSOLUTE_PATH_TO_CLONE_TO`,
Run: lsFunc,
}
func lsFunc(cmd *cobra.Command, argz []string) {
if len(argz) == 0 {
listGhorgHome()
}
if len(argz) >= 1 {
for _, arg := range argz {
listGhorgDir(arg)
}
}
}
func listGhorgHome() {
path := os.Getenv("GHORG_ABSOLUTE_PATH_TO_CLONE_TO")
files, err := ioutil.ReadDir(path)
if err != nil {
colorlog.PrintError("No clones found. Please clone some and try again.")
}
for _, f := range files {
if f.IsDir() {
colorlog.PrintInfo(path + f.Name())
}
}
}
func listGhorgDir(arg string) {
arg = strings.ReplaceAll(arg, "-", "_")
path := os.Getenv("GHORG_ABSOLUTE_PATH_TO_CLONE_TO") + arg
files, err := ioutil.ReadDir(path)
if err != nil {
colorlog.PrintError("No clone found with that name. Please check spelling or reclone.")
}
for _, f := range files {
if f.IsDir() {
str := filepath.Join(path, configs.GetCorrectFilePathSeparator(), f.Name())
colorlog.PrintSubtleInfo(str)
}
}
}