forked from gabrie30/ghorg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (58 loc) · 1.48 KB
/
main.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
package main
import (
"fmt"
"log"
"os"
"github.com/gabrie30/ghorg/cmd"
"github.com/gabrie30/ghorg/colorlog"
"github.com/gabrie30/ghorg/config"
"github.com/joho/godotenv"
homedir "github.com/mitchellh/go-homedir"
)
func init() {
if len(os.Args) <= 1 {
log.Fatal("You must provide an org to clone from")
}
home, err := homedir.Dir()
if err != nil {
log.Fatal("Error trying to find users home directory")
}
err = godotenv.Load(home + "/.ghorg")
if err != nil {
fmt.Println()
colorlog.PrintSubtleInfo("Could not find a $HOME/.ghorg proceeding with defaults")
}
config.GitHubToken = os.Getenv("GHORG_GITHUB_TOKEN")
config.AbsolutePathToCloneTo = os.Getenv("GHORG_ABSOLUTE_PATH_TO_CLONE_TO")
config.GhorgBranch = os.Getenv("GHORG_BRANCH")
config.GhorgCloneProtocol = os.Getenv("GHORG_CLONE_PROTOCOL")
if config.GhorgBranch == "" {
config.GhorgBranch = "master"
}
if config.AbsolutePathToCloneTo == "" {
config.AbsolutePathToCloneTo = home + "/Desktop/"
}
if config.GhorgCloneProtocol == "" {
config.GhorgCloneProtocol = "https"
}
withTrailingSlash := ensureTrailingSlash(config.AbsolutePathToCloneTo)
config.AbsolutePathToCloneTo = withTrailingSlash
}
func ensureTrailingSlash(path string) string {
if string(path[len(path)-1]) == "/" {
return path
}
return path + "/"
}
func asciiTime() {
colorlog.PrintInfo(
`
+-+-+-+-+ +-+-+ +-+-+-+-+-+
|T|I|M|E| |T|O| |G|H|O|R|G|
+-+-+-+-+ +-+-+ +-+-+-+-+-+
`)
}
func main() {
asciiTime()
cmd.CloneAllReposByOrg()
}