Skip to content

Commit 6d747bd

Browse files
committed
project init added
1 parent 6a400f7 commit 6d747bd

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

controllers/functions.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TimeLog() {
3333
cmd.Run()
3434
}
3535

36-
func ProgramStarting(cnf *string, filepath string, modOrFile string, command string, help *bool, version string) (string, string) {
36+
func ProgramStarting(cnf *string, filepath string, modOrFile string, command string, help *bool, version string, init bool, name string, oso string, arch string) (string, string) {
3737
if *cnf == "cmd" {
3838

3939
} else if *cnf == "cnf" {
@@ -64,11 +64,36 @@ func ProgramStarting(cnf *string, filepath string, modOrFile string, command str
6464
arch := "GOARCH=" + pr.Arch
6565
name := pr.Name
6666
os.Chdir(pr.Path)
67+
fmt.Println(pr)
6768
cmd := exec.Command("env", goos, arch, "go", "build", "-o", name)
6869
cmd.Stdout = os.Stdout
6970
cmd.Stderr = os.Stderr
7071
cmd.Run()
7172
os.Exit(1)
73+
} else if init == true {
74+
os.Mkdir(name, 0777)
75+
os.Chdir(name)
76+
var project models.Project
77+
path, _ := os.Getwd()
78+
project.Path = path
79+
project.Name = name
80+
project.Arch = arch
81+
project.OS = oso
82+
var commands models.Commands
83+
var command models.Command
84+
command.Name = "run"
85+
command.Path = path
86+
command.Option = "mod"
87+
commands.Commands = append(commands.Commands, command)
88+
file, _ := json.MarshalIndent(project, "", " ")
89+
_ = ioutil.WriteFile("project.json", file, 0644)
90+
file, _ = json.MarshalIndent(commands, "", " ")
91+
_ = ioutil.WriteFile("godemon-cnf.json", file, 0644)
92+
cmd := exec.Command("go", "mod", "init", name)
93+
cmd.Stdout = os.Stdout
94+
cmd.Stderr = os.Stderr
95+
cmd.Run()
96+
os.Exit(1)
7297
} else if *help == true {
7398
fmt.Printf("Godemon %v: \n 1. -cnf <- in this flag put info about what do you want to do - if use cmd option use -cnf=cmd, if config file use -cnf=cnf \n 2. -path <- path to file/directory \n 3. -modOrFile <- are you using modules or one file \n 4. -command <- binded command in config file \n", version)
7499
os.Exit(1)

controllers/loadFlags.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,26 @@ import (
44
"flag"
55
)
66

7-
func LoadCMD(filepath string, modOrFile string) (string, string, string, string, *bool) {
7+
func LoadCMD(filepath string, modOrFile string) (string, string, string, string, *bool, bool, string, string, string) {
88
var filepathP *string
99
var modOrFileP *string
1010
cnfP := flag.String("cnf", "", "a string")
1111
filepathP = flag.String("path", "", "a string")
1212
commandP := flag.String("command", "", "a string")
1313
helpP := flag.Bool("help", false, "a bool")
14+
initP := flag.Bool("init", false, "a bool")
15+
nameP := flag.String("name", "", "a string")
16+
osP := flag.String("os", "", "a string")
17+
archP := flag.String("arch", "", "a string")
1418
modOrFileP = flag.String("modOrFile", "", "a string")
1519
flag.Parse()
1620
cnf := *cnfP
1721
filepath = *filepathP
22+
init := *initP
23+
name := *nameP
24+
os := *osP
25+
arch := *archP
1826
command := *commandP
1927
modOrFile = *modOrFileP
20-
return filepath, modOrFile, cnf, command, helpP
28+
return filepath, modOrFile, cnf, command, helpP, init, name, os, arch
2129
}

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
)
99

1010
func main() {
11-
version := "2.0.0"
11+
version := "2.1.0"
1212
doneChan := make(chan bool)
13-
filepath, modOrFile, cnf, command, help := controllers.LoadCMD("", "")
14-
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version)
13+
filepath, modOrFile, cnf, command, help, init, name, oso, arch := controllers.LoadCMD("", "")
14+
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version, init, name, oso, arch)
1515
for true {
1616
go func(doneChan chan bool) {
1717
defer func() {

0 commit comments

Comments
 (0)