MCPcopy
hub / github.com/owenthereal/ccat / stripFlags

Function stripFlags

Godeps/_workspace/src/github.com/spf13/cobra/command.go:323–361  ·  view source on GitHub ↗
(args []string, c *Command)

Source from the content-addressed store, hash-verified

321}
322
323func stripFlags(args []string, c *Command) []string {
324 if len(args) < 1 {
325 return args
326 }
327 c.mergePersistentFlags()
328
329 commands := []string{}
330
331 inQuote := false
332 inFlag := false
333 for _, y := range args {
334 if !inQuote {
335 switch {
336 case strings.HasPrefix(y, "\""):
337 inQuote = true
338 case strings.Contains(y, "=\""):
339 inQuote = true
340 case strings.HasPrefix(y, "--") && !strings.Contains(y, "="):
341 // TODO: this isn't quite right, we should really check ahead for 'true' or 'false'
342 inFlag = !isBooleanFlag(y[2:], c.Flags())
343 case strings.HasPrefix(y, "-") && !strings.Contains(y, "=") && len(y) == 2 && !isBooleanShortFlag(y[1:], c.Flags()):
344 inFlag = true
345 case inFlag:
346 inFlag = false
347 case y == "":
348 // strip empty commands, as the go tests expect this to be ok....
349 case !strings.HasPrefix(y, "-"):
350 commands = append(commands, y)
351 inFlag = false
352 }
353 }
354
355 if strings.HasSuffix(y, "\"") && !strings.HasSuffix(y, "\\\"") {
356 inQuote = false
357 }
358 }
359
360 return commands
361}
362
363// argsMinusFirstX removes only the first x from args. Otherwise, commands that look like
364// openshift admin policy add-role-to-user admin my-user, lose the admin argument (arg[4]).

Callers 2

TestStripFlagsFunction · 0.85
FindMethod · 0.85

Calls 4

isBooleanFlagFunction · 0.85
isBooleanShortFlagFunction · 0.85
mergePersistentFlagsMethod · 0.80
FlagsMethod · 0.80

Tested by 1

TestStripFlagsFunction · 0.68