MCPcopy Index your code
hub / github.com/cli/cli / parseArgs

Function parseArgs

internal/codespaces/ssh.go:153–174  ·  view source on GitHub ↗

parseArgs parses arguments into two distinct slices of flags and command. Parsing stops as soon as a non-flag argument is found assuming the remaining arguments are the command. It returns an error if a unary flag is provided without an argument.

(args []string, unaryFlags string)

Source from the content-addressed store, hash-verified

151// as soon as a non-flag argument is found assuming the remaining arguments are the command.
152// It returns an error if a unary flag is provided without an argument.
153func parseArgs(args []string, unaryFlags string) (cmdArgs, command []string, err error) {
154 for i := 0; i < len(args); i++ {
155 arg := args[i]
156
157 // if we've started parsing the command, set it to the rest of the args
158 if !strings.HasPrefix(arg, "-") {
159 command = args[i:]
160 break
161 }
162
163 cmdArgs = append(cmdArgs, arg)
164 if len(arg) == 2 && strings.Contains(unaryFlags, arg[1:2]) {
165 if i++; i == len(args) {
166 return nil, nil, fmt.Errorf("flag: %s requires an argument", arg)
167 }
168
169 cmdArgs = append(cmdArgs, args[i])
170 }
171 }
172
173 return cmdArgs, command, nil
174}

Callers 2

ParseSSHArgsFunction · 0.85
parseSCPArgsFunction · 0.85

Calls 2

ContainsMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected