parseWithName parses flags for a command whose name argument normally comes first, which would otherwise stop flag parsing. It returns the name.
(fs *flag.FlagSet, args []string)
| 108 | // parseWithName parses flags for a command whose name argument normally comes |
| 109 | // first, which would otherwise stop flag parsing. It returns the name. |
| 110 | func parseWithName(fs *flag.FlagSet, args []string) (string, error) { |
| 111 | var name string |
| 112 | rest := args |
| 113 | if len(args) > 0 && !strings.HasPrefix(args[0], "-") { |
| 114 | name, rest = args[0], args[1:] |
| 115 | } |
| 116 | if err := fs.Parse(rest); err != nil { |
| 117 | return "", usageError{err} |
| 118 | } |
| 119 | extra := fs.Args() |
| 120 | if name == "" && len(extra) > 0 { |
| 121 | name, extra = extra[0], extra[1:] |
| 122 | } |
| 123 | if len(extra) > 0 { |
| 124 | hint := "" |
| 125 | if !strings.Contains(name, " ") && strings.HasPrefix(extra[0], "/") { |
| 126 | hint = fmt.Sprintf("; quote the request name, such as '%s %s'", name, extra[0]) |
| 127 | } |
| 128 | return "", newUsageError("unexpected arguments: %s%s", strings.Join(extra, " "), hint) |
| 129 | } |
| 130 | return name, nil |
| 131 | } |
| 132 | |
| 133 | // validateName checks that a request name looks like "graphql Operation" or |
| 134 | // "METHOD /path". |
no test coverage detected