Switch to flag library

This commit is contained in:
maride 2020-06-09 18:01:46 +02:00
parent b58017d4f7
commit 3a738edc23
2 changed files with 16 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"log" "log"
"net/http" "net/http"
@ -9,6 +10,10 @@ import (
// Main function // Main function
func main() { func main() {
// Register flags
registerWatcherFlags()
flag.Parse()
// Check args // Check args
targetFuzzers, targetErr := getFuzzersToWatch() targetFuzzers, targetErr := getFuzzersToWatch()
if targetErr != nil { if targetErr != nil {

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"log" "log"
"os" "os"
@ -9,15 +10,19 @@ import (
var ( var (
registeredFuzzers []Fuzzer 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 // Returns the path to every fuzzer to watch
func getFuzzersToWatch() ([]string, error) { func getFuzzersToWatch() ([]string, error) {
for i, a := range os.Args { // flag.Args() returns all arguments after --
if a == "--" { fuzzers := flag.Args()
// Choose arguments after that one as the target fuzzer directories if len(fuzzers) > 0 {
return os.Args[i+1:], nil return fuzzers, nil
}
} }
// Wrong usage - construct a helpful error message // Wrong usage - construct a helpful error message
@ -50,6 +55,6 @@ func watchFuzzers() {
} }
// and sleep // and sleep
time.Sleep(30 * time.Second) time.Sleep(time.Duration(*sleepSecs) * time.Second)
} }
} }