MCPcopy Create free account
hub / github.com/cli/cli / parseWithName

Function parseWithName

script/ghmock/set.go:110–131  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

108// parseWithName parses flags for a command whose name argument normally comes
109// first, which would otherwise stop flag parsing. It returns the name.
110func 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".

Callers 5

parseSetArgsFunction · 0.85
parseScaffoldArgsFunction · 0.85
parseSchemaArgsFunction · 0.85
parseRepoArgsFunction · 0.85
parseWriteArgsFunction · 0.85

Calls 3

newUsageErrorFunction · 0.85
ContainsMethod · 0.80
JoinMethod · 0.80

Tested by

no test coverage detected