Skip to content

Commit ed7715b

Browse files
committed
added cnf json files support
1 parent a30167a commit ed7715b

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

main.go

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

33
import (
4+
"encoding/json"
45
"fmt"
56
"godemon/controllers"
7+
"godemon/models"
8+
"io/ioutil"
69
"os"
710
"os/exec"
811
"time"
@@ -36,8 +39,28 @@ func watch(fileordirPath string) error {
3639

3740
func main() {
3841
doneChan := make(chan bool)
39-
filepath := os.Args[1]
40-
modOrFile := os.Args[2]
42+
cnf := os.Args[1]
43+
var filepath string
44+
var modOrFile string
45+
if cnf == "cmd" {
46+
filepath = os.Args[2]
47+
modOrFile = os.Args[3]
48+
} else if cnf == "cnf" {
49+
command := os.Args[2]
50+
jsonFile, _ := os.Open("godemon-cnf.json")
51+
byteValue, _ := ioutil.ReadAll(jsonFile)
52+
var commands models.Commands
53+
json.Unmarshal(byteValue, &commands)
54+
for i := 0; i < len(commands.Commands); i++ {
55+
if command == commands.Commands[i].Name {
56+
fmt.Println(commands.Commands[i].Path)
57+
fmt.Println(commands.Commands[i].Option)
58+
filepath = commands.Commands[i].Path
59+
modOrFile = commands.Commands[i].Option
60+
}
61+
}
62+
jsonFile.Close()
63+
}
4164
fmt.Println(filepath)
4265
for true {
4366
go func(doneChan chan bool) {

models/cnf.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package models
2+
3+
type Command struct {
4+
Name string `json:"name"`
5+
Path string `json:"path"`
6+
Option string `json:"file"`
7+
}
8+
9+
type Commands struct {
10+
Commands []Command `json:"commands"`
11+
}

0 commit comments

Comments
 (0)