Skip to content

Commit 0dde8f5

Browse files
committed
added flags
1 parent 42cf72e commit 0dde8f5

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

controllers/functions.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ func TimeLog() {
3333
cmd.Run()
3434
}
3535

36-
func ProgramStarting(cnf string, filepath string, modOrFile string) (string, string) {
37-
if cnf == "cmd" {
38-
filepath = os.Args[2]
39-
modOrFile = os.Args[3]
40-
} else if cnf == "cnf" {
41-
command := os.Args[2]
36+
func ProgramStarting(cnf *string, filepath string, modOrFile string, command string, help *bool, version string) (string, string) {
37+
if *cnf == "cmd" {
38+
39+
} else if *cnf == "cnf" {
4240
jsonFile, err := os.Open("godemon-cnf.json")
4341
ErrorHandle(err)
4442
defer jsonFile.Close()
@@ -54,6 +52,9 @@ func ProgramStarting(cnf string, filepath string, modOrFile string) (string, str
5452
modOrFile = commands.Commands[i].Option
5553
}
5654
}
55+
} else if *help == true {
56+
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)
57+
os.Exit(1)
5758
}
5859
return filepath, modOrFile
5960
}

controllers/loadFlags.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package controllers
2+
3+
import (
4+
"flag"
5+
)
6+
7+
func LoadCMD(filepath string, modOrFile string) (string, string, string, string, *bool) {
8+
var filepathP *string
9+
var modOrFileP *string
10+
cnfP := flag.String("cnf", "", "a string")
11+
filepathP = flag.String("path", "", "a string")
12+
commandP := flag.String("command", "", "a string")
13+
helpP := flag.Bool("help", false, "a bool")
14+
modOrFileP = flag.String("modOrFile", "", "a string")
15+
flag.Parse()
16+
cnf := *cnfP
17+
filepath = *filepathP
18+
command := *commandP
19+
modOrFile = *modOrFileP
20+
return filepath, modOrFile, cnf, command, helpP
21+
}

main.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import (
88
)
99

1010
func main() {
11+
version := "2.0.0"
1112
doneChan := make(chan bool)
12-
cnf := os.Args[1]
13-
var filepath string
14-
var modOrFile string
15-
filepath, modOrFile = controllers.ProgramStarting(cnf, filepath, modOrFile)
16-
fmt.Println(filepath)
13+
filepath, modOrFile, cnf, command, help := controllers.LoadCMD("", "")
14+
filepath, modOrFile = controllers.ProgramStarting(&cnf, filepath, modOrFile, command, help, version)
1715
for true {
1816
go func(doneChan chan bool) {
1917
defer func() {

0 commit comments

Comments
 (0)