From 886a02d4a9029bbd0653eb07eea272cfadb43da2 Mon Sep 17 00:00:00 2001 From: Andre Lehmann Date: Wed, 24 Aug 2022 13:25:43 +0200 Subject: [PATCH] fix: panic when providing an empty string as an argument --- cmd.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd.go b/cmd.go index eccebda..17d88fa 100644 --- a/cmd.go +++ b/cmd.go @@ -443,7 +443,7 @@ func (c *Command) innerDispatch(args []string) (err error) { name := args[0] // ensure is not an option - if name[0] != '-' { + if name != "" && name[0] != '-' { name = c.ResolveAlias(name) // is valid sub command @@ -452,7 +452,7 @@ func (c *Command) innerDispatch(args []string) (err error) { return sub.innerDispatch(args[1:]) } - // no arguments, name is not founded subcommand + // is not a sub command and has no arguments -> error if !c.HasArguments() { // fire events if stop := c.Fire(EvtCmdSubNotFound, name); stop { @@ -464,8 +464,6 @@ func (c *Command) innerDispatch(args []string) (err error) { color.Error.Tips("subcommand '%s' - not found on the command", name) } - } else { - name = "" // reset var } }