From 3a738edc23d4f11932133bd913b564b840658a3c Mon Sep 17 00:00:00 2001 From: maride Date: Tue, 9 Jun 2020 18:01:46 +0200 Subject: [PATCH] Switch to flag library --- main.go | 5 +++++ watch.go | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index dd8ebec..0be5353 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "log" "net/http" @@ -9,6 +10,10 @@ import ( // Main function func main() { + // Register flags + registerWatcherFlags() + flag.Parse() + // Check args targetFuzzers, targetErr := getFuzzersToWatch() if targetErr != nil { diff --git a/watch.go b/watch.go index 1a2cca1..8ff7f02 100644 --- a/watch.go +++ b/watch.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "log" "os" @@ -9,15 +10,19 @@ import ( var ( registeredFuzzers []Fuzzer + sleepSecs *int ) +func registerWatcherFlags() { + sleepSecs = flag.Int("scan-delay", 30, "Seconds to sleep between scans of the fuzzer directories") +} + // Returns the path to every fuzzer to watch func getFuzzersToWatch() ([]string, error) { - for i, a := range os.Args { - if a == "--" { - // Choose arguments after that one as the target fuzzer directories - return os.Args[i+1:], nil - } + // flag.Args() returns all arguments after -- + fuzzers := flag.Args() + if len(fuzzers) > 0 { + return fuzzers, nil } // Wrong usage - construct a helpful error message @@ -50,6 +55,6 @@ func watchFuzzers() { } // and sleep - time.Sleep(30 * time.Second) + time.Sleep(time.Duration(*sleepSecs) * time.Second) } }