Skip to content

Commit

Permalink
Merge pull request #21 from bgp/feature/abort-on-leftover-positional-…
Browse files Browse the repository at this point in the history
…args

Abort when positional arguments are provided
  • Loading branch information
job authored Aug 27, 2021
2 parents 4fbaebe + 4d3afc7 commit 7af1293
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cmd/rtrdump/rtrdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cmd/rtrmon/rtrmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cmd/stayrtr/stayrtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7af1293

Please sign in to comment.