-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.go
57 lines (50 loc) · 1.37 KB
/
new.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
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/go-git/go-git/v5"
"github.com/urfave/cli/v2"
)
const (
IBC_APP_SOLIDITY_TEMPLATE_REPO = "https://github.com/open-ibc/ibc-app-solidity-template"
)
func newCmd(c *cli.Context) error {
projectName := c.Args().First()
projectRoot := c.String("path")
dstPath := filepath.Join(projectRoot, projectName)
// given project root already exists
if _, err := os.Stat(dstPath); err == nil {
if c.Bool("force") {
err = os.RemoveAll(dstPath)
if err != nil {
return err
}
} else {
dstAbsPath, _ := filepath.Abs(dstPath)
return fmt.Errorf("provided project root[%s] already exists, please check it", dstAbsPath)
}
}
cloneOpts := &git.CloneOptions{
URL: IBC_APP_SOLIDITY_TEMPLATE_REPO,
Progress: os.Stdout,
}
if c.Bool("recurse") {
cloneOpts.RecurseSubmodules = git.DefaultSubmoduleRecursionDepth
}
fmt.Println("Cloning template.....")
_, err := git.PlainClone(dstPath, false, cloneOpts)
if err != nil {
return err
}
fmt.Println("Cloned successfully")
if err = os.RemoveAll(filepath.Join(dstPath, ".git")); err != nil {
return err
}
if err = os.Rename(filepath.Join(dstPath, ".env.example"), filepath.Join(dstPath, ".env")); err != nil {
return err
}
projectRootAbs, _ := filepath.Abs(dstPath)
fmt.Printf("Create new project success!!!\nProject root: %s\n", projectRootAbs)
return nil
}