From f2752f560971fb69512c7d3106d4809d287a42ff Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 4 Nov 2024 21:23:45 +0000 Subject: [PATCH] print usage message if not in interactive mode, and no rcon commands passed --- cmd/q3rcon/main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/q3rcon/main.go b/cmd/q3rcon/main.go index 61a5a2f..790bfe5 100644 --- a/cmd/q3rcon/main.go +++ b/cmd/q3rcon/main.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "errors" "flag" "fmt" "io" @@ -16,6 +17,12 @@ import ( var interactive bool +func exit(err error) { + _, _ = fmt.Fprintf(os.Stderr, "Error: %s\n", err) + flag.Usage() + os.Exit(1) +} + func main() { var ( host string @@ -57,6 +64,11 @@ func main() { return } + if len(flag.Args()) == 0 { + err = errors.New("no rcon commands passed") + exit(err) + } + for _, arg := range flag.Args() { resp, err := rcon.Send(arg) if err != nil {