Determine if a token looks like a flag. Unless an argument has nargs set to argparse.REMAINDER, then anything that looks like a flag can't be consumed as a value for it. Based on argparse._parse_optional().
(token: str, parser: Cmd2ArgumentParser)
| 70 | |
| 71 | |
| 72 | def _looks_like_flag(token: str, parser: Cmd2ArgumentParser) -> bool: |
| 73 | """Determine if a token looks like a flag. |
| 74 | |
| 75 | Unless an argument has nargs set to argparse.REMAINDER, then anything that looks like a flag |
| 76 | can't be consumed as a value for it. |
| 77 | |
| 78 | Based on argparse._parse_optional(). |
| 79 | """ |
| 80 | # Flags have to be at least characters |
| 81 | if len(token) < 2: |
| 82 | return False |
| 83 | |
| 84 | # Flags have to start with a prefix character |
| 85 | if token[0] not in parser.prefix_chars: |
| 86 | return False |
| 87 | |
| 88 | # If it looks like a negative number, it is not a flag unless there are negative-number-like flags |
| 89 | if parser._negative_number_matcher.match(token) and not parser._has_negative_number_optionals: |
| 90 | return False |
| 91 | |
| 92 | # Flags can't have a space |
| 93 | return " " not in token |
| 94 | |
| 95 | |
| 96 | class _ArgumentState: |
no outgoing calls
searching dependent graphs…