Skip to content

Commit

Permalink
fix: guard against nil os.Args (#70)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 authored Mar 6, 2024
1 parent 915be52 commit 4417dfb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/bursa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] <subcommand> [args]\n\nSubcommands:\n\n",
"Usage: %s [-h] <subcommand> [args]\n\nSubcommands:\n\n",
appName,
)
fmt.Fprintf(
flag.CommandLine.Output(),
Expand All @@ -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
Expand Down

0 comments on commit 4417dfb

Please sign in to comment.