-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (43 loc) · 1.16 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
package main
import (
"fmt"
"os"
"github.com/AaronCQL/gitget/pkg/gitget"
"github.com/spf13/pflag"
)
const (
success string = "\033[32m✓"
critical string = "\033[31m✕"
)
func main() {
pflag.Usage = func() {
fmt.Printf("Usage: gitget REPO_URL [OPTIONS...]\n")
pflag.PrintDefaults()
}
cfg := gitget.Config{}
pflag.StringVarP(&cfg.Dir, "dir", "d", "", "The target directory to clone into")
pflag.StringVarP(&cfg.Branch, "branch", "b", "", "Git branch to clone")
pflag.StringVarP(&cfg.Commit, "commit", "c", "", "Git commit hash to clone")
pflag.StringVarP(&cfg.Tag, "tag", "t", "", "Git tag to clone")
pflag.BoolVarP(&cfg.Force, "force", "f", false, "Forcefully write files into the existing target directory")
help := pflag.BoolP("help", "h", false, "Display this help message")
pflag.Parse()
if *help {
pflag.Usage()
os.Exit(0)
}
args := pflag.Args()
if len(args) != 1 {
pflag.Usage()
os.Exit(1)
}
res, err := gitget.Clone(args[0], cfg)
if err != nil {
fmt.Printf("%v %v\n", critical, err)
os.Exit(1)
}
fmt.Printf(
"%v cloned %v/%v (%v) into %v\n",
success, res.RepoOwner, res.RepoName, res.RepoFragment, res.TargetDirRel,
)
}