mirror of
https://github.com/spf13/cobra
synced 2025-05-05 21:07:24 +00:00
Simplify stripFlags
This commit is contained in:
parent
aac12021de
commit
04373829fc
1 changed files with 15 additions and 24 deletions
|
@ -430,17 +430,13 @@ func stripFlags(args []string, c *Command) []string {
|
||||||
c.mergePersistentFlags()
|
c.mergePersistentFlags()
|
||||||
|
|
||||||
commands := []string{}
|
commands := []string{}
|
||||||
inQuote := false
|
|
||||||
flags := c.Flags()
|
flags := c.Flags()
|
||||||
|
|
||||||
Loop:
|
Loop:
|
||||||
for len(args) > 0 {
|
for len(args) > 0 {
|
||||||
s := args[0]
|
s := args[0]
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
if !inQuote {
|
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(s, "\"") || strings.Contains(s, "=\""):
|
|
||||||
inQuote = true
|
|
||||||
case strings.HasPrefix(s, "--") && !strings.Contains(s, "=") && !hasNoOptDefVal(s[2:], flags):
|
case strings.HasPrefix(s, "--") && !strings.Contains(s, "=") && !hasNoOptDefVal(s[2:], flags):
|
||||||
// If '--flag arg' then
|
// If '--flag arg' then
|
||||||
// delete arg from args.
|
// delete arg from args.
|
||||||
|
@ -459,11 +455,6 @@ Loop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasSuffix(s, "\"") && !strings.HasSuffix(s, "\\\"") {
|
|
||||||
inQuote = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue