| 32 | | Options may be in two forms: long and short. Short options start with a single |
|---|
| 33 | | dash and are one letter long. Long options start with two dashes and may |
|---|
| 34 | | consist of any number of characters (so long as they don't start with a dash, |
|---|
| 35 | | though they may contain dashes). Options are case-sensitive. |
|---|
| | 32 | Options may be in three forms: long and short and slash. Short options start |
|---|
| | 33 | with a single dash and are one letter long. Long options start with two dashes |
|---|
| | 34 | and may consist of any number of characters (so long as they don't start with a |
|---|
| | 35 | dash, though they may contain dashes). Slash options start with a single |
|---|
| | 36 | forward slash, and may also consist of any number of characters. All options |
|---|
| | 37 | are case-sensitive. |
|---|
| | 347 | } else if (opt.startswith("/")) { |
|---|
| | 348 | idx = find(opt, '='); |
|---|
| | 349 | if (idx != -1) { |
|---|
| | 350 | newopt = opt[0 .. idx]; |
|---|
| | 351 | // Stitch out the old arg, stitch in the newopt, arg pair. |
|---|
| | 352 | args = args[0 .. i] ~ [newopt, opt[idx+1 .. $]] ~ args[i+1 .. $]; |
|---|
| | 353 | opt = newopt; |
|---|
| | 354 | } |
|---|
| | 355 | for (int j=0; j<opt.length;) { |
|---|
| | 356 | idx = j; |
|---|
| | 357 | j = find(opt[j+1 .. $], '/'); |
|---|
| | 358 | if (j == -1) { |
|---|
| | 359 | j = opt.length; |
|---|
| | 360 | } else { |
|---|
| | 361 | j += idx+1; // We searched for j in a slice of opt, remember. |
|---|
| | 362 | } |
|---|
| | 363 | newopt = opt[idx .. j]; |
|---|
| | 364 | match = matches(newopt); |
|---|
| | 365 | if (match is null) { |
|---|
| | 366 | unknown_opt_error(newopt); |
|---|
| | 367 | } |
|---|
| | 368 | if (match.hasArg) { |
|---|
| | 369 | // If this isn't the last opt in a group, or if it is |
|---|
| | 370 | // the last element in args, we don't have a valid |
|---|
| | 371 | // argument. |
|---|
| | 372 | if (j < opt.length || i == args.length-1) |
|---|
| | 373 | expected_arg_error(match.name); |
|---|
| | 374 | arg = args[i+1]; |
|---|
| | 375 | ++i; |
|---|
| | 376 | } else { |
|---|
| | 377 | arg = null; |
|---|
| | 378 | } |
|---|
| | 379 | match.perform_action(options, arg); |
|---|
| | 380 | } |
|---|