-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
76 lines (63 loc) · 1.66 KB
/
Copy pathmain.go
File metadata and controls
76 lines (63 loc) · 1.66 KB
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
package main
import (
"log"
"os"
"os/exec"
"time"
"github.com/AlecAivazis/survey/v2"
"github.com/onattech/go-starter/embed"
"github.com/onattech/go-starter/utils"
)
func init() {
log.SetFlags(log.Ltime | log.Lshortfile)
}
const (
defaultProjectName = "go-my-project"
path1 = "/coding/myProjects/GO"
githubAccount = "github.com/onattech/"
)
func main() {
// Perform the questions for local repo
answers := utils.LocalQS(path1, defaultProjectName, githubAccount)
// Make project folder
err := os.Mkdir(answers.PathDirname+"/"+answers.PathBasename, 0755)
if err != nil {
log.Fatal(err)
}
// Add main.go file
mainGO, _ := embed.FS.ReadFile("files/main.go")
os.WriteFile(answers.FullPath+"/main.go", mainGO, 0644)
// Go mode init
goCmdPath := "/usr/local/go/bin/go"
cmd := exec.Command(goCmdPath, "mod", "init", githubAccount+answers.PathBasename)
cmd.Dir = answers.FullPath
err = cmd.Run()
if err != nil {
log.Println("err", err)
}
// Initialize git
utils.GitInit(answers.FullPath)
// Ask if user want to initialize a repo
var github bool
prompt := &survey.Confirm{
Message: "Would you like to initialize a github repo?",
Default: true,
}
survey.AskOne(prompt, &github)
// Quit if the user doesn't want a github repo
if !github {
log.Println("✅ Local repo initialized, starting vscode")
time.Sleep(time.Second)
// Start vscode
cmd = exec.Command("code", answers.PathDirname+"/"+answers.PathBasename)
cmd.Run()
return
}
utils.GithubQS(cmd, answers)
// Start vscode
cmd = exec.Command("code", answers.PathDirname+"/"+answers.PathBasename)
e := cmd.Run()
if e != nil {
log.Println("can't start vscode", e)
}
}