From d364ed015706a7e72df064bfb3d39e1a644f0f98 Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Fri, 3 Dec 2021 02:53:30 +0800 Subject: [PATCH] Only delete arg when it is not starts with - Signed-off-by: JaySon-Huang --- command.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/command.go b/command.go index 2cc18891..1da9df6b 100644 --- a/command.go +++ b/command.go @@ -585,11 +585,12 @@ Loop: case strings.HasPrefix(s, "-") && !strings.Contains(s, "=") && len(s) == 2 && !shortHasNoOptDefVal(s[1:], flags): // If '-f arg' then // delete 'arg' from args or break the loop if len(args) <= 1. - if len(args) <= 1 { + if len(args) == 0 { break Loop - } else { + } + // Only delete 'arg' when it is not starts with '-' + if !strings.HasPrefix(args[0], "-") { args = args[1:] - continue } case s != "" && !strings.HasPrefix(s, "-"): commands = append(commands, s)