Skip to content

Commit 856d9cb

Browse files
committed
reverted
1 parent 742921e commit 856d9cb

File tree

9 files changed

+70
-211
lines changed

9 files changed

+70
-211
lines changed

controllers/execsAndBuild.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

controllers/functions.go

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,60 @@
11
package controllers
22

33
import (
4+
"encoding/json"
5+
"fmt"
46
"godemon/models"
7+
"io/ioutil"
58
"os"
9+
"os/exec"
610
"time"
711
)
812

9-
func ProgramStarting(cnf *string, filepath string, modOrFile string, command string, help *bool, version string, init *bool, name string) (string, string) {
13+
func ExecMOD() {
14+
cmd := exec.Command("./app-godemon-app-godemon-tmp-generated")
15+
cmd.Stdout = os.Stdout
16+
cmd.Stderr = os.Stderr
17+
cmd.Run()
18+
}
19+
20+
func ExecFile(filepath string) {
21+
cmd := exec.Command("go", "run", filepath)
22+
cmd.Stdout = os.Stdout
23+
cmd.Stderr = os.Stderr
24+
cmd.Run()
25+
}
26+
27+
func TimeLog() {
28+
log := time.Now().Format("2006-01-02, 15:04 \n\n")
29+
log = `Building project: ` + log + `Program result: `
30+
cmd := exec.Command("printf", "\\e[1;34m%-6s\\e[m\n", log)
31+
cmd.Stdout = os.Stdout
32+
cmd.Stderr = os.Stderr
33+
cmd.Run()
34+
}
35+
36+
func ProgramStarting(cnf *string, filepath string, modOrFile string, command string, help *bool, version string) (string, string) {
1037
if *cnf == "cmd" {
1138

1239
} else if *cnf == "cnf" {
13-
filepath, modOrFile = loadDataFromCnf(cnf, command, "", "")
14-
} else if *cnf == "deploy" {
15-
_, _ = loadDataFromCnf(cnf, command, "", "")
16-
} else if *init == true {
17-
initialization(name)
40+
jsonFile, err := os.Open("godemon-cnf.json")
41+
ErrorHandle(err)
42+
defer jsonFile.Close()
43+
byteValue, err := ioutil.ReadAll(jsonFile)
44+
ErrorHandle(err)
45+
var commands models.Commands
46+
json.Unmarshal(byteValue, &commands)
47+
for i := 0; i < len(commands.Commands); i++ {
48+
if command == commands.Commands[i].Name {
49+
fmt.Println(commands.Commands[i].Path)
50+
fmt.Println(commands.Commands[i].Option)
51+
filepath = commands.Commands[i].Path
52+
modOrFile = commands.Commands[i].Option
53+
}
54+
}
1855
} else if *help == true {
19-
models.Help(version)
56+
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)
57+
os.Exit(1)
2058
}
2159
return filepath, modOrFile
2260
}
@@ -32,7 +70,10 @@ func WatchFiles(fileordirPath string) error {
3270
return err
3371
}
3472
if stat.Size() != initialStat.Size() || stat.ModTime() != initialStat.ModTime() {
35-
killProcess()
73+
cmd := exec.Command("killall", "-9", "app-godemon-app-godemon-tmp-generated")
74+
cmd.Stdout = os.Stdout
75+
cmd.Stderr = os.Stderr
76+
cmd.Run()
3677
break
3778
}
3879
time.Sleep(1 * time.Second)

controllers/loadFlags.go

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

7-
func LoadCMD(filepath string, modOrFile string) (string, string, string, string, *bool, *bool, string) {
7+
func LoadCMD(filepath string, modOrFile string) (string, string, string, string, *bool) {
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")
1614
modOrFileP = flag.String("modOrFile", "", "a string")
1715
flag.Parse()
1816
cnf := *cnfP
1917
filepath = *filepathP
2018
command := *commandP
21-
name := *nameP
2219
modOrFile = *modOrFileP
23-
if cnf == "" {
24-
*helpP = true
25-
}
26-
return filepath, modOrFile, cnf, command, helpP, initP, name
20+
return filepath, modOrFile, cnf, command, helpP
2721
}

controllers/privatesFuncs.go

Lines changed: 0 additions & 87 deletions
This file was deleted.

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=

main.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package main
33
import (
44
"fmt"
55
"godemon/controllers"
6-
"godemon/models"
76
"os"
7+
"os/exec"
88
)
99

1010
func main() {
11-
version := "2.0.6"
11+
version := "2.0.0"
1212
doneChan := make(chan bool)
13-
filepath, modOrFile, cnf, command, help, init, name := controllers.LoadCMD("", "")
14-
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version, init, name)
13+
filepath, modOrFile, cnf, command, help := controllers.LoadCMD("", "")
14+
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version)
1515
for true {
1616
go func(doneChan chan bool) {
1717
defer func() {
@@ -24,11 +24,14 @@ func main() {
2424
fmt.Println("File has been changed")
2525
if modOrFile == "mod" {
2626
os.Chdir(filepath)
27-
models.TimeLog()
28-
controllers.BuildMod()
27+
controllers.TimeLog()
28+
cmd := exec.Command("go", "build", "-o", "app-godemon-app-godemon-tmp-generated")
29+
cmd.Stdout = os.Stdout
30+
cmd.Stderr = os.Stderr
31+
cmd.Run()
2932
go controllers.ExecMOD()
3033
} else if modOrFile == "file" {
31-
models.TimeLog()
34+
controllers.TimeLog()
3235
go controllers.ExecFile(filepath)
3336
}
3437
}(doneChan)

models/cnf.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ type Command struct {
66
Option string `json:"file"`
77
}
88

9-
type Project struct {
10-
Name string `json:"name"`
11-
OS string `json:"platformOS"`
12-
Arch string `json:"platformArch"`
13-
Path string `json:"path"`
14-
}
15-
169
type Commands struct {
1710
Commands []Command `json:"commands"`
1811
}
19-
20-
type ProjectInfo struct {
21-
Project Project `json:"project"`
22-
Commands Commands
23-
}

models/staticCLI.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

readme.md

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,13 @@ If you need help with clie use command `./godemon -help`
4040

4141
```
4242
{
43-
"project": {
44-
"name": "api2",
45-
"platformOS": "linux",
46-
"platformArch": "amd64",
47-
"path": "/home/nwagner/Desktop/godemon/api/"
48-
},
49-
"commands": [
50-
{
51-
"name": "run",
52-
"path": "/home/nwagner/Desktop/godemon/api/",
53-
"file": "mod"
54-
},
55-
{
56-
"name": "run-single-file",
57-
"path": "/home/nwagner/Desktop/godemon/api/main.go",
58-
"option": "file"
59-
}
60-
]
43+
"commands": [
44+
{
45+
"name": "run",
46+
"path": "/home/nwagner/Desktop/godemon/api/",
47+
"file": "mod"
48+
}
49+
]
6150
}
6251
```
63-
3. Now use command: `godemon -cnf=cnf -command=<command-name>` or if you want to make full binary
64-
file you need to use command: `godemon -cnf=deploy`. This will create
65-
binary file with env variables. Deploy is using command - `env GOOS=project.platformOS
66-
GOARCH=projet.platformArch go build -o project.name`
52+
3. Now use command: `godemon -cnf=cnf -command=<command-name>`

0 commit comments

Comments
 (0)