Skip to content

Commit e889789

Browse files
committed
Adding tracking files by cli
1 parent 61038af commit e889789

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

cliTools/loadFlags.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"go/build"
77
)
88

9-
func LoadCMD(filepath string, modOrFile string) (string, string, string, string, *bool, bool, string, string, string, string) {
9+
func LoadCMD(filepath string, modOrFile string) (string, string, string, string, *bool, bool, string, string, string, string, bool) {
1010
var filepathP *string
1111
cmd := flag.Bool("cmd", false, "a bool")
1212
cnfM := flag.Bool("cnf", false, "a bool")
@@ -20,8 +20,10 @@ func LoadCMD(filepath string, modOrFile string) (string, string, string, string,
2020
archP := flag.String("arch", "", "a string")
2121
mod := flag.Bool("mod", false, "a bool")
2222
file := flag.Bool("file", false, "a bool")
23+
addFileM := flag.Bool("addFile",false,"a bool")
2324
flag.Parse()
2425
cnf := ""
26+
addFile := false
2527
if *cmd == true {
2628
cnf = "cmd"
2729
} else if *cnfM == true {
@@ -30,6 +32,8 @@ func LoadCMD(filepath string, modOrFile string) (string, string, string, string,
3032
cnf = "deploy"
3133
} else if (*cmd == true && *cnfM == true) || (*cmd == true && *deploy == true) || (*cnfM == true && *deploy == true) {
3234
color.Red("Too many mode parameters")
35+
} else if *addFileM == true {
36+
addFile = true
3337
}
3438
filepath = *filepathP
3539
init := *initP
@@ -63,5 +67,5 @@ func LoadCMD(filepath string, modOrFile string) (string, string, string, string,
6367
if *cnfM == true && *commandP == "" {
6468
color.Red("You must specify a command")
6569
}
66-
return filepath, modOrFile, cnf, command, helpP, init, name, os, arch, cont
70+
return filepath, modOrFile, cnf, command, helpP, init, name, os, arch, cont, addFile
6771
}

controllers/functions.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"godemon/models"
55
)
66

7-
func ProgramStarting(cnf *string, filepath string, modOrFile string, command string, help *bool, version string, init bool, name string, oso string, arch string, hOS string) (string, string) {
7+
func ProgramStarting(cnf *string, filepath string, modOrFile string, command string, help *bool, version string, init bool, name string, oso string, arch string, hOS string, addFile bool) (string, string) {
88
if *cnf == "cmd" {
99

1010
} else if *cnf == "cnf" {
@@ -13,6 +13,8 @@ func ProgramStarting(cnf *string, filepath string, modOrFile string, command str
1313
deploy(oso, arch, hOS)
1414
} else if init == true {
1515
initialize(name, arch, oso)
16+
} else if addFile == true {
17+
addFileJson(name,filepath)
1618
} else if *help == true ||
1719
(*cnf == "" && filepath == "" && modOrFile == "" &&
1820
command == "" && *help == false && init == false &&

controllers/pv.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"godemon/models"
88
"godemon/prepareProject"
99
"io/ioutil"
10+
"bytes"
1011
"os"
1112
"os/exec"
1213
)
@@ -75,4 +76,18 @@ func cnfFunc(command string, filepath string, modOrFile string) (string, string)
7576
}
7677
cliTools.CheckModOrPath(modOrFile, filepath)
7778
return filepath, modOrFile
79+
}
80+
81+
func addFileJson(name string, path string){
82+
var project models.Project
83+
var file models.File
84+
file.Name = name
85+
file.Path = path
86+
data, _ := ioutil.ReadFile("project.json")
87+
json.Unmarshal(data,&project)
88+
project.Files = append(project.Files,file)
89+
var bytes = new(bytes.Buffer)
90+
json.NewEncoder(bytes).Encode(project)
91+
ioutil.WriteFile("project.json",bytes.Bytes(),0644)
92+
os.Exit(1)
7893
}

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ func main() {
2626
version := "21.04"
2727
color.HiMagenta("Welcome to godemon " + version)
2828
doneChan := make(chan bool)
29-
filepath, modOrFile, cnf, command, help, init, name, oso, arch, cont := cliTools.LoadCMD("", "")
29+
filepath, modOrFile, cnf, command, help, init, name, oso, arch, cont, addFile := cliTools.LoadCMD("", "")
3030
if cont == "Exit" {
3131
os.Exit(1)
3232
}
33-
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version, init, name, oso, arch, hostInfo[0])
33+
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version, init, name, oso, arch, hostInfo[0], addFile)
3434
for true {
3535
go func(doneChan chan bool) {
3636
defer func() {

0 commit comments

Comments
 (0)