Skip to content

Commit 484be48

Browse files
committed
Warning
1 parent b98e152 commit 484be48

File tree

6 files changed

+58
-63
lines changed

6 files changed

+58
-63
lines changed

cliTools/loadFlags.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import (
44
"flag"
55
"github.com/fatih/color"
66
"go/build"
7-
os1 "os"
87
)
98

10-
func LoadCMD(filepath string, modOrFile string) (string, string, string, string, *bool, bool, string, string, string, string, bool, bool) {
9+
func LoadCMD(filepath string, modOrFile string) (string, string, string, string, *bool, bool, string, string, string, string) {
1110
var filepathP *string
1211
cmd := flag.Bool("cmd", false, "a bool")
1312
cnfM := flag.Bool("cnf", false, "a bool")
@@ -21,8 +20,6 @@ func LoadCMD(filepath string, modOrFile string) (string, string, string, string,
2120
archP := flag.String("arch", "", "a string")
2221
mod := flag.Bool("mod", false, "a bool")
2322
file := flag.Bool("file", false, "a bool")
24-
addCmd := flag.Bool("addCmd", false, "a bool")
25-
addFile := flag.Bool("addFile", false, "a bool")
2623
flag.Parse()
2724
cnf := ""
2825
if *cmd == true {
@@ -33,7 +30,6 @@ func LoadCMD(filepath string, modOrFile string) (string, string, string, string,
3330
cnf = "deploy"
3431
} else if (*cmd == true && *cnfM == true) || (*cmd == true && *deploy == true) || (*cnfM == true && *deploy == true) {
3532
color.Red("Too many mode parameters")
36-
os1.Exit(1)
3733
}
3834
filepath = *filepathP
3935
init := *initP
@@ -45,14 +41,7 @@ func LoadCMD(filepath string, modOrFile string) (string, string, string, string,
4541
if *mod == true {
4642
modOrFile = "mod"
4743
} else if *file == true {
48-
modOrFile = "file"
49-
}
50-
if *cmd == true && filepath == "" {
51-
color.Red("Path is empty")
52-
os1.Exit(1)
53-
} else if *cmd == true && *file == false && *mod == false {
54-
color.Red("You didn't define is it file or module")
55-
os1.Exit(1)
44+
modOrFile = "mod"
5645
}
5746
cont := ""
5847
if init == true && name == "" {
@@ -68,9 +57,8 @@ func LoadCMD(filepath string, modOrFile string) (string, string, string, string,
6857
os = build.Default.GOOS
6958
}
7059
}
71-
if *deploy == true && (*file == true || *cmd == true || *cnfM == true || *filepathP != "" || *commandP != "" || *helpP == true || *initP == true || *nameP != "" || *osP != "" || *archP != "" || *mod == true) {
60+
if *deploy == true && (*file==true || *cmd == true || *cnfM==true || *filepathP != "" || *commandP != "" || *helpP ==true || *initP==true || *nameP!="" || *osP != "" || *archP != "" || *mod ==true){
7261
color.Red("Warning!!! Deploy takes only deploy argument")
73-
os1.Exit(1)
7462
}
75-
return filepath, modOrFile, cnf, command, helpP, init, name, os, arch, cont, *addCmd, *addFile
63+
return filepath, modOrFile, cnf, command, helpP, init, name, os, arch, cont
7664
}

controllers/watch.go

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

3-
func WatchFiles(fileordirPath string, hOS string, cnf string) error {
4-
return watch(fileordirPath, hOS, cnf)
3+
func WatchFiles(fileordirPath string, hOS string) error {
4+
return watch(fileordirPath, hOS)
55
}

controllers/watchPv.go

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,35 @@ import (
99
"time"
1010
)
1111

12-
func watch(fileordirPath string, hOS string, cnf string) error {
13-
if cnf == "cnf" {
14-
files := prepareProject.LoadProjectInfo().Files
15-
j := 0
16-
var initStats []os.FileInfo
17-
for j < len(files) {
18-
stat, err := os.Stat(strings.TrimSpace(files[j].Path))
19-
errors.ErrorHandle(err)
20-
initStats = append(initStats, stat)
21-
j++
22-
}
23-
g := 0
24-
for {
25-
i := 0
26-
for i < len(files) {
27-
stat, err := os.Stat(strings.TrimSpace(files[i].Path))
28-
if err != nil {
29-
return err
30-
}
31-
if stat.Size() != initStats[i].Size() || stat.ModTime() != initStats[i].ModTime() {
32-
killProcess.KillProcess(hOS)
33-
g = 1
34-
break
35-
}
36-
i++
37-
}
38-
if g == 1 {
39-
break
40-
}
41-
time.Sleep(1 * time.Second)
42-
}
43-
} else if cnf == "cmd" {
44-
initStat, err := os.Stat(fileordirPath)
45-
if err != nil {
46-
return err
47-
}
48-
for {
49-
stat, err := os.Stat(fileordirPath)
12+
func watch(fileordirPath string, hOS string) error {
13+
files := prepareProject.LoadProjectInfo().Files
14+
j := 0
15+
var initStats []os.FileInfo
16+
for j < len(files) {
17+
stat, err := os.Stat(strings.TrimSpace(files[j].Path))
18+
errors.ErrorHandle(err)
19+
initStats = append(initStats, stat)
20+
j++
21+
}
22+
g := 0
23+
for {
24+
i := 0
25+
for i < len(files) {
26+
stat, err := os.Stat(strings.TrimSpace(files[i].Path))
5027
if err != nil {
5128
return err
5229
}
53-
if stat.Size() != initStat.Size() || stat.ModTime() != initStat.ModTime() {
30+
if stat.Size() != initStats[i].Size() || stat.ModTime() != initStats[i].ModTime() {
5431
killProcess.KillProcess(hOS)
32+
g = 1
5533
break
5634
}
35+
i++
36+
}
37+
if g == 1 {
38+
break
5739
}
40+
time.Sleep(1 * time.Second)
5841
}
5942
return nil
6043
}

main.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//TODO - golang delve support
44
//TODO - create new README.md
55
//TODO - create new WIKI
6-
//TODO - add functions that edit project.json from cli
6+
//TODO - add CMD option support
77

88
package main
99

@@ -16,7 +16,6 @@ import (
1616
"godemon/errors"
1717
"godemon/execs"
1818
"godemon/hotReload"
19-
"godemon/infoUpdate"
2019
"os"
2120
"os/exec"
2221
)
@@ -27,18 +26,17 @@ func main() {
2726
version := "21.04"
2827
color.HiMagenta("Welcome to godemon " + version)
2928
doneChan := make(chan bool)
30-
filepath, modOrFile, cnf, command, help, init, name, oso, arch, cont, addCmd, addFile := cliTools.LoadCMD("", "")
29+
filepath, modOrFile, cnf, command, help, init, name, oso, arch, cont := cliTools.LoadCMD("", "")
3130
if cont == "Exit" {
3231
os.Exit(1)
3332
}
34-
infoUpdate.Update(addCmd, addFile, name, modOrFile, filepath)
3533
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version, init, name, oso, arch, hostInfo[0])
3634
for true {
3735
go func(doneChan chan bool) {
3836
defer func() {
3937
doneChan <- true
4038
}()
41-
err := controllers.WatchFiles(filepath, hostInfo[0], cnf)
39+
err := controllers.WatchFiles(filepath, hostInfo[0])
4240
errors.ErrorHandle(err)
4341
fmt.Println("File has been changed")
4442
if modOrFile == "mod" {

models/cnf.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package models
2+
3+
type Command struct {
4+
Name string `json:"name"`
5+
Option string `json:"file"`
6+
Path string `json:"path"` // optional, for single file support
7+
}
8+
9+
type Var struct {
10+
Key string `json:"key"`
11+
Value string `json:"value"`
12+
}
13+
14+
type Project struct {
15+
Name string `json:"name"`
16+
Arch string `json:"arch"`
17+
OS string `json:"os"`
18+
Vars []Var `json:"dev-vars"`
19+
Commands []Command `json:"commands"`
20+
Files []File `json:"files"`
21+
}
22+
23+
type File struct {
24+
Name string `json:"name"`
25+
Path string `json:"path"`
26+
}

models/staticCLI.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import (
88

99
func HelpCLI(version string) {
1010
color.Green("Godemon %v:", version)
11-
fmt.Println("to do -cnf -cmd -deploy -path -command -help -init -name -os -arch -mod -file") //("\n 1. -cnf <- in this flag put info about what do you want to do - if use cmd just -cmd option, if config file use -cnf \n2. -path <- path to file/directory \n 3. -modOrFile <- are you using modules or one file \n 4. -command <- binded command in config file \n 5. -name <- name of project \n 6. -os <- OS platform \n 7. -arch <- architecture \n 8. -init <- initializazition of project \n\n Have a problem? Go on my GitHub and see the README.md - https://github.com/Godemon-simplify-your-Go-programming/godemon \n")
11+
fmt.Println("to do -cnf -cmd -deploy -path -command -help -init -name -os -arch -mod -file")//("\n 1. -cnf <- in this flag put info about what do you want to do - if use cmd just -cmd option, if config file use -cnf \n2. -path <- path to file/directory \n 3. -modOrFile <- are you using modules or one file \n 4. -command <- binded command in config file \n 5. -name <- name of project \n 6. -os <- OS platform \n 7. -arch <- architecture \n 8. -init <- initializazition of project \n\n Have a problem? Go on my GitHub and see the README.md - https://github.com/Godemon-simplify-your-Go-programming/godemon \n")
1212
os.Exit(1)
1313
}

0 commit comments

Comments
 (0)