From 4d3afc715324c9e72e785c74976b977198335a20 Mon Sep 17 00:00:00 2001 From: Ties de Kock Date: Fri, 27 Aug 2021 12:44:49 +0200 Subject: [PATCH] Abort when positional arguments are provided --- cmd/rtrdump/rtrdump.go | 14 ++++++++++---- cmd/rtrmon/rtrmon.go | 4 ++++ cmd/stayrtr/stayrtr.go | 4 ++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/rtrdump/rtrdump.go b/cmd/rtrdump/rtrdump.go index 0bc2137..949af20 100644 --- a/cmd/rtrdump/rtrdump.go +++ b/cmd/rtrdump/rtrdump.go @@ -6,15 +6,17 @@ import ( "errors" "flag" "fmt" - rtr "github.com/bgp/stayrtr/lib" - "github.com/bgp/stayrtr/prefixfile" - log "github.com/sirupsen/logrus" - "golang.org/x/crypto/ssh" "io" "io/ioutil" "net" "os" "runtime" + "strings" + + rtr "github.com/bgp/stayrtr/lib" + "github.com/bgp/stayrtr/prefixfile" + log "github.com/sirupsen/logrus" + "golang.org/x/crypto/ssh" ) const ( @@ -127,6 +129,10 @@ func main() { runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() + if flag.NArg() > 0 { + fmt.Printf("%s: illegal positional argument(s) provided (\"%s\") - did you mean to provide a flag?\n", os.Args[0], strings.Join(flag.Args(), " ")) + os.Exit(2) + } if *Version { fmt.Println(AppVersion) os.Exit(0) diff --git a/cmd/rtrmon/rtrmon.go b/cmd/rtrmon/rtrmon.go index 3792485..fe540f1 100644 --- a/cmd/rtrmon/rtrmon.go +++ b/cmd/rtrmon/rtrmon.go @@ -768,6 +768,10 @@ func main() { runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() + if flag.NArg() > 0 { + fmt.Printf("%s: illegal positional argument(s) provided (\"%s\") - did you mean to provide a flag?\n", os.Args[0], strings.Join(flag.Args(), " ")) + os.Exit(2) + } if *Version { fmt.Println(AppVersion) os.Exit(0) diff --git a/cmd/stayrtr/stayrtr.go b/cmd/stayrtr/stayrtr.go index 910c1db..bb88836 100644 --- a/cmd/stayrtr/stayrtr.go +++ b/cmd/stayrtr/stayrtr.go @@ -487,6 +487,10 @@ func main() { runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() + if flag.NArg() > 0 { + fmt.Printf("%s: illegal positional argument(s) provided (\"%s\") - did you mean to provide a flag?\n", os.Args[0], strings.Join(flag.Args(), " ")) + os.Exit(2) + } if *Version { fmt.Println(AppVersion) os.Exit(0)