From 7ec7bf8d81f1974c2f605d7b0f9b130725482d78 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Thu, 27 Jun 2019 21:08:08 +0200 Subject: [PATCH] feat: add option not --- is_master.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/is_master.go b/is_master.go index ffb4b35..3bdafad 100644 --- a/is_master.go +++ b/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") }