(chars)
| 498 | |
| 499 | def visitword(self, node, word): |
| 500 | def attemptfuzzy(chars): |
| 501 | m = [] |
| 502 | if chars[0] == "-": |
| 503 | tokens = [chars[0:2]] + list(chars[2:]) |
| 504 | consider_arg = True |
| 505 | else: |
| 506 | tokens = list(chars) |
| 507 | consider_arg = False |
| 508 | |
| 509 | pos = node.pos[0] |
| 510 | prev_option = None |
| 511 | for i, t in enumerate(tokens): |
| 512 | op = t if t[0] == "-" else "-" + t |
| 513 | option = self.find_option(op) |
| 514 | if option: |
| 515 | if consider_arg and not m and option.has_argument: |
| 516 | logger.info( |
| 517 | "option %r expected an arg, taking the rest too", option |
| 518 | ) |
| 519 | # reset the current option if we already took an argument, |
| 520 | # this prevents the next word node to also consider itself |
| 521 | # as an argument |
| 522 | self._current_option = None |
| 523 | return [ |
| 524 | MatchResult( |
| 525 | pos, |
| 526 | pos + len(chars), |
| 527 | option.text, |
| 528 | None, |
| 529 | _option_debug(option), |
| 530 | ) |
| 531 | ] |
| 532 | |
| 533 | mr = MatchResult( |
| 534 | pos, pos + len(t), option.text, None, _option_debug(option) |
| 535 | ) |
| 536 | m.append(mr) |
| 537 | # if the previous option expected an argument and we couldn't |
| 538 | # match the current token, take the rest as its argument, this |
| 539 | # covers a series of short options where the last one has an argument |
| 540 | # with no space between it, such as 'xargs -r0n1' |
| 541 | elif consider_arg and prev_option and prev_option.has_argument: |
| 542 | pmr = m[-1] |
| 543 | mr = MatchResult( |
| 544 | pmr.start, |
| 545 | pmr.end + (len(tokens) - i), |
| 546 | pmr.text, |
| 547 | None, |
| 548 | pmr.debug_info, |
| 549 | ) |
| 550 | m[-1] = mr |
| 551 | # reset the current option if we already took an argument, |
| 552 | # this prevents the next word node to also consider itself |
| 553 | # as an argument |
| 554 | self._current_option = None |
| 555 | break |
| 556 | else: |
| 557 | m.append(self.unknown(t, pos, pos + len(t))) |
nothing calls this directly
no test coverage detected