(self, token: str)
| 270 | return not has_value |
| 271 | |
| 272 | def handle(self, token: str) -> None: |
| 273 | debug("Handling token: {!r}".format(token)) |
| 274 | # Handle unknown state at the top: we don't care about even |
| 275 | # possibly-valid input if we've encountered unknown input. |
| 276 | if self.current_state == "unknown": |
| 277 | debug("Top-of-handle() see_unknown({!r})".format(token)) |
| 278 | self.see_unknown(token) |
| 279 | return |
| 280 | # Flag |
| 281 | if self.context and token in self.context.flags: |
| 282 | debug("Saw flag {!r}".format(token)) |
| 283 | self.switch_to_flag(token) |
| 284 | elif self.context and token in self.context.inverse_flags: |
| 285 | debug("Saw inverse flag {!r}".format(token)) |
| 286 | self.switch_to_flag(token, inverse=True) |
| 287 | # Value for current flag |
| 288 | elif self.waiting_for_flag_value: |
| 289 | debug( |
| 290 | "We're waiting for a flag value so {!r} must be it?".format( |
| 291 | token |
| 292 | ) |
| 293 | ) # noqa |
| 294 | self.see_value(token) |
| 295 | # Positional args (must come above context-name check in case we still |
| 296 | # need a posarg and the user legitimately wants to give it a value that |
| 297 | # just happens to be a valid context name.) |
| 298 | elif self.context and self.context.missing_positional_args: |
| 299 | msg = "Context {!r} requires positional args, eating {!r}" |
| 300 | debug(msg.format(self.context, token)) |
| 301 | self.see_positional_arg(token) |
| 302 | # New context |
| 303 | elif token in self.contexts: |
| 304 | self.see_context(token) |
| 305 | # Initial-context flag being given as per-task flag (e.g. --help) |
| 306 | elif self.initial and token in self.initial.flags: |
| 307 | debug("Saw (initial-context) flag {!r}".format(token)) |
| 308 | flag = self.initial.flags[token] |
| 309 | # Special-case for core --help flag: context name is used as value. |
| 310 | if flag.name == "help": |
| 311 | flag.value = self.context.name |
| 312 | msg = "Saw --help in a per-task context, setting task name ({!r}) as its value" # noqa |
| 313 | debug(msg.format(flag.value)) |
| 314 | # All others: just enter the 'switch to flag' parser state |
| 315 | else: |
| 316 | # TODO: handle inverse core flags too? There are none at the |
| 317 | # moment (e.g. --no-dedupe is actually 'no_dedupe', not a |
| 318 | # default-False 'dedupe') and it's up to us whether we actually |
| 319 | # put any in place. |
| 320 | self.switch_to_flag(token) |
| 321 | # Unknown |
| 322 | else: |
| 323 | if not self.ignore_unknown: |
| 324 | debug("Can't find context named {!r}, erroring".format(token)) |
| 325 | self.error("No idea what {!r} is!".format(token)) |
| 326 | else: |
| 327 | debug("Bottom-of-handle() see_unknown({!r})".format(token)) |
| 328 | self.see_unknown(token) |
| 329 |
no test coverage detected