Skip to content

Commit 007cfdd

Browse files
author
norbertwagner
committed
Added new functionality
1 parent ef9326b commit 007cfdd

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

cliTools/loadFlags.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
os1 "os"
88
)
99

10-
func LoadCMD(filepath string, modOrFile string) (string, string, string, string, *bool, bool, string, string, string, string, bool) {
10+
func LoadCMD(filepath string, modOrFile string) (string, string, string, string, *bool, bool, string, string, string, string, bool, bool) {
1111
var filepathP *string
1212
cmd := flag.Bool("cmd", false, "a bool")
1313
cnfM := flag.Bool("cnf", false, "a bool")
@@ -22,6 +22,7 @@ func LoadCMD(filepath string, modOrFile string) (string, string, string, string,
2222
mod := flag.Bool("mod", false, "a bool")
2323
file := flag.Bool("file", false, "a bool")
2424
addCmd := flag.Bool("addCmd", false, "a bool")
25+
addFile := flag.Bool("addFile", false, "a bool")
2526
flag.Parse()
2627
cnf := ""
2728
if *cmd == true {
@@ -71,5 +72,5 @@ func LoadCMD(filepath string, modOrFile string) (string, string, string, string,
7172
color.Red("Warning!!! Deploy takes only deploy argument")
7273
os1.Exit(1)
7374
}
74-
return filepath, modOrFile, cnf, command, helpP, init, name, os, arch, cont, *addCmd
75+
return filepath, modOrFile, cnf, command, helpP, init, name, os, arch, cont, *addCmd, *addFile
7576
}

infoUpdate/infoUpdate.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package infoUpdate
2+
3+
import (
4+
"fmt"
5+
"godemon/prepareProject"
6+
"os"
7+
)
8+
9+
func Update(addCmd bool, addFile bool, name string, modOrFile string, filepath string) {
10+
if addCmd == true && name != "" && modOrFile != "" {
11+
prepareProject.ModifyJSONCommands(modOrFile, name, filepath)
12+
fmt.Println("Info updated")
13+
os.Exit(1)
14+
}
15+
if addFile == true && name != "" && filepath != "" {
16+
prepareProject.ModifyJSONFiles(name, filepath)
17+
fmt.Println("Info updated")
18+
os.Exit(1)
19+
}
20+
}

main.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"godemon/errors"
1717
"godemon/execs"
1818
"godemon/hotReload"
19-
"godemon/prepareProject"
19+
"godemon/infoUpdate"
2020
"os"
2121
"os/exec"
2222
)
@@ -27,15 +27,11 @@ func main() {
2727
version := "21.04"
2828
color.HiMagenta("Welcome to godemon " + version)
2929
doneChan := make(chan bool)
30-
filepath, modOrFile, cnf, command, help, init, name, oso, arch, cont, addCmd := cliTools.LoadCMD("", "")
30+
filepath, modOrFile, cnf, command, help, init, name, oso, arch, cont, addCmd, addFile := cliTools.LoadCMD("", "")
3131
if cont == "Exit" {
3232
os.Exit(1)
3333
}
34-
if addCmd == true && name != "" && modOrFile != "" {
35-
prepareProject.ModifyJSONCommands(modOrFile, name, filepath)
36-
fmt.Println("Info updated")
37-
os.Exit(1)
38-
}
34+
infoUpdate.Update(addCmd, addFile, name, modOrFile, filepath)
3935
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version, init, name, oso, arch, hostInfo[0])
4036
for true {
4137
go func(doneChan chan bool) {

prepareProject/jsonUpdate.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,15 @@ func ModifyJSONCommands(option string, name string, path string) {
1919
err = ioutil.WriteFile("project.json", file, 0644)
2020
errors.ErrorHandle(err)
2121
}
22+
23+
func ModifyJSONFiles(name string, path string) {
24+
project := LoadProjectInfo()
25+
var fileJ models.File
26+
fileJ.Name = name
27+
fileJ.Path = path
28+
project.Files = append(project.Files, fileJ)
29+
file, err := json.MarshalIndent(project, "", " ")
30+
errors.ErrorHandle(err)
31+
err = ioutil.WriteFile("project.json", file, 0644)
32+
errors.ErrorHandle(err)
33+
}

0 commit comments

Comments
 (0)