MCPcopy Create free account
hub / github.com/docopt/docopt.go / parseOption

Function parseOption

docopt.go:236–267  ·  view source on GitHub ↗
(optionDescription string)

Source from the content-addressed store, hash-verified

234}
235
236func parseOption(optionDescription string) *pattern {
237 optionDescription = strings.TrimSpace(optionDescription)
238 options, _, description := stringPartition(optionDescription, " ")
239 options = strings.Replace(options, ",", " ", -1)
240 options = strings.Replace(options, "=", " ", -1)
241
242 short := ""
243 long := ""
244 argcount := 0
245 var value interface{}
246 value = false
247
248 reDefault := regexp.MustCompile(`(?i)\[default: (.*)\]`)
249 for _, s := range strings.Fields(options) {
250 if strings.HasPrefix(s, "--") {
251 long = s
252 } else if strings.HasPrefix(s, "-") {
253 short = s
254 } else {
255 argcount = 1
256 }
257 if argcount > 0 {
258 matched := reDefault.FindAllStringSubmatch(description, -1)
259 if len(matched) > 0 {
260 value = matched[0][1]
261 } else {
262 value = nil
263 }
264 }
265 }
266 return newOption(short, long, argcount, value)
267}
268
269func parseExpr(tokens *tokenList, options *patternList) (patternList, error) {
270 // expr ::= seq ( '|' seq )* ;

Callers 2

parseDefaultsFunction · 0.85
TestOptionFunction · 0.85

Calls 2

stringPartitionFunction · 0.85
newOptionFunction · 0.85

Tested by 1

TestOptionFunction · 0.68