feat: add option not
This commit is contained in:
parent
c6aaebc509
commit
7ec7bf8d81
1 changed files with 13 additions and 4 deletions
17
is_master.go
17
is_master.go
|
@ -16,6 +16,7 @@ var (
|
|||
IP = flag.String("ip", "", "")
|
||||
FILE = flag.String("file", "", "")
|
||||
COMMAND = flag.String("command", "", "command to execute")
|
||||
NOT = flag.Bool("not", false, "execute the command if the ip or the file isn't present")
|
||||
)
|
||||
|
||||
// Critical print a message and exit with code 2
|
||||
|
@ -86,15 +87,23 @@ func ipExist(ip string) bool {
|
|||
}
|
||||
|
||||
func main() {
|
||||
var isMaster bool
|
||||
var execute bool
|
||||
|
||||
if *FILE != "" {
|
||||
isMaster = fileExist(*FILE)
|
||||
execute = fileExist(*FILE)
|
||||
} else {
|
||||
isMaster = ipExist(*IP)
|
||||
execute = ipExist(*IP)
|
||||
}
|
||||
|
||||
if isMaster == false {
|
||||
if *NOT {
|
||||
if execute {
|
||||
execute = false
|
||||
} else {
|
||||
execute = true
|
||||
}
|
||||
}
|
||||
|
||||
if execute {
|
||||
Ok("I have nothing to do, i going to sleep")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue