@@ -37,21 +37,9 @@ func ProgramStarting(cnf *string, filepath string, modOrFile string, command str
3737 if * cnf == "cmd" {
3838
3939 } else if * cnf == "cnf" {
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- }
40+ filepath , modOrFile = loadDataFromCnf (cnf , command , "" , "" )
41+ } else if * cnf == "deploy" {
42+ _ , _ = loadDataFromCnf (cnf , command , "" , "" )
5543 } else if * help == true {
5644 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 )
5745 os .Exit (1 )
@@ -91,3 +79,48 @@ func killProcess() {
9179 cmd .Stderr = os .Stderr
9280 cmd .Run ()
9381}
82+
83+ func loadDataFromCnf (cnf * string , command string , filepath string , modOrFile string ) (string , string ) {
84+ jsonFile , err := os .Open ("godemon-cnf.json" )
85+ ErrorHandle (err )
86+ defer jsonFile .Close ()
87+ byteValue , err := ioutil .ReadAll (jsonFile )
88+ ErrorHandle (err )
89+ var projectInfo models.ProjectInfo
90+ json .Unmarshal (byteValue , & projectInfo )
91+ if * cnf == "cnf" {
92+ commandsL := projectInfo .Commands .Commands
93+ for i := 0 ; i < len (commandsL ); i ++ {
94+ if command == commandsL [i ].Name {
95+ fmt .Println (commandsL [i ].Path )
96+ fmt .Println (commandsL [i ].Option )
97+ filepath = commandsL [i ].Path
98+ modOrFile = commandsL [i ].Option
99+ }
100+ }
101+ } else if * cnf == "deploy" {
102+ log := time .Now ().Format ("2006-01-02, 15:04 \n \n " )
103+ log = `Building project: ` + log + `: `
104+ cmd := exec .Command ("printf" , "\\ e[1;34m%-6s\\ e[m\n " , log )
105+ cmd .Stdout = os .Stdout
106+ cmd .Stderr = os .Stderr
107+ cmd .Run ()
108+ path := projectInfo .Project .Path
109+ osP := projectInfo .Project .OS
110+ arch := projectInfo .Project .Arch
111+ goos := "GOOS=" + osP
112+ archos := "GOARCH=" + arch
113+ name := projectInfo .Project .Name
114+ os .Chdir (path )
115+ cmd = exec .Command ("env" , goos , archos , "go" , "build" , "-o" , name )
116+ cmd .Stdout = os .Stdout
117+ cmd .Stderr = os .Stderr
118+ cmd .Run ()
119+ cmd = exec .Command ("printf" , "\\ e[1;34m%-6s\\ e[m\n " , "Project builded" )
120+ cmd .Stdout = os .Stdout
121+ cmd .Stderr = os .Stderr
122+ cmd .Run ()
123+ os .Exit (1 )
124+ }
125+ return filepath , modOrFile
126+ }
0 commit comments