From 767c7ec7c5a318d4045cfb03605794a66656576d Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Wed, 6 Mar 2024 16:32:41 -0500 Subject: [PATCH] fix: guard against nil os.Args Signed-off-by: Chris Gianelloni --- cmd/bursa/main.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/bursa/main.go b/cmd/bursa/main.go index b39a090..d18ab8b 100644 --- a/cmd/bursa/main.go +++ b/cmd/bursa/main.go @@ -24,11 +24,18 @@ import ( ) func main() { - fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError) + var appName string + if os.Args == nil { + appName = "bursa" + } else { + appName = os.Args[0] + } + fs := flag.NewFlagSet(appName, flag.ExitOnError) fs.Usage = func() { fmt.Fprintf( flag.CommandLine.Output(), - "Usage: bursa [-h] [args]\n\nSubcommands:\n\n", + "Usage: %s [-h] [args]\n\nSubcommands:\n\n", + appName, ) fmt.Fprintf( flag.CommandLine.Output(), @@ -43,6 +50,10 @@ func main() { "run a terminal command", ) } + if os.Args == nil { + fs.Usage() + os.Exit(1) + } _ = fs.Parse(os.Args[1:]) // ignore parse errors // Load Config