-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (85 loc) · 1.87 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"github.com/urfave/cli"
"log"
"os"
"os/user"
)
func main() {
app := cli.NewApp()
app.Name = "seeder"
app.Usage = "copy source from remote repository"
app.Version = "0.0.1"
usr, _ := user.Current()
defaultKey := usr.HomeDir + "/.ssh/id_rsa"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "branch, b",
Usage: "Git branch",
},
cli.StringFlag{
Name: "clone-cdir, c",
Usage: "temp directory where repo will be cloned; \"memory\" to use system memory",
FilePath: "/tmp",
Value: "/tmp",
},
cli.StringFlag{
Name: "ssh-key, k",
Usage: "private ssh key to use (default: \"" + defaultKey + "\")",
},
cli.StringFlag{
Name: "github-proto, p",
Usage: "Github proto; auto, https, or ssh",
Value: "auto",
},
cli.BoolFlag{
Name: "preserve-git, g",
Usage: "preserve .git directory",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "quiet mode, no output",
},
cli.BoolFlag{
Name: "verbose, v",
Usage: "verbose mode for troubleshooting",
},
}
cli.VersionFlag = cli.BoolFlag{
Name: "version, V",
Usage: "print the version",
}
app.Action = func(c *cli.Context) error {
ci := ConfigInput{}
ci.target = c.Args().Get(0)
ci.src = c.Args().Get(1)
ci.dst = c.Args().Get(2)
ci.branch = c.String("branch")
ci.cdir = c.String("clone-cdir")
ci.key = c.String("ssh-key")
ci.proto = c.String("github-proto")
ci.git = c.Bool("preserve-git")
ci.quiet = c.Bool("quiet")
ci.verbose = c.Bool("verbose")
s, err := NewSeed(ci)
if err != nil {
println("Unable to retrieve seed")
println(err.Error())
}
err = s.clone()
if err != nil {
println("Unable to clone project")
println(err.Error())
}
err = s.process()
if err != nil {
println("Unable to copy files")
println(err.Error())
}
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}