-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (50 loc) · 1 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 (
"errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"log"
"os"
"path"
"strings"
)
func NewCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "degit",
Short: "degit is scafollding tool using git repository",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("repository is not specified")
}
u, err := toURL(args[0])
if err != nil {
return err
}
prefix := ""
dest := path.Base(strings.TrimSuffix(u.Path, ".git"))
if len(args) == 2 {
prefix = args[1]
if !strings.Contains(prefix, "/") {
dest = prefix
}
} else if len(args) == 3 {
prefix = args[1]
dest = args[2]
}
// TODO support windows
if !strings.HasSuffix(prefix, "/") {
prefix = prefix + "/"
}
l := logrus.New()
l.SetLevel(logrus.InfoLevel)
return Clone(l, u, prefix, dest)
},
}
return cmd
}
func main() {
if err := NewCommand().Execute(); err != nil {
log.Println(err)
os.Exit(1)
}
}