MCPcopy Index your code
hub / github.com/pyinvoke/invoke / parse_cleanup

Method parse_cleanup

invoke/program.py:490–550  ·  view source on GitHub ↗

Post-parsing, pre-execution steps such as --help, --list, etc. .. versionadded:: 1.0

(self)

Source from the content-addressed store, hash-verified

488 # TODO: load project conf, if possible, gracefully
489
490 def parse_cleanup(self) -> None:
491 """
492 Post-parsing, pre-execution steps such as --help, --list, etc.
493
494 .. versionadded:: 1.0
495 """
496 halp = self.args.help.value
497
498 # Core (no value given) --help output (only when bundled namespace)
499 if halp is True:
500 debug("Saw bare --help, printing help & exiting")
501 self.print_help()
502 raise Exit
503
504 # Print per-task help, if necessary
505 if halp:
506 if halp in self.parser.contexts:
507 msg = "Saw --help <taskname>, printing per-task help & exiting"
508 debug(msg)
509 self.print_task_help(halp)
510 raise Exit
511 else:
512 # TODO: feels real dumb to factor this out of Parser, but...we
513 # should?
514 raise ParseError("No idea what '{}' is!".format(halp))
515
516 # Print discovered tasks if necessary
517 list_root = self.args.list.value # will be True or string
518 self.list_format = self.args["list-format"].value
519 self.list_depth = self.args["list-depth"].value
520 if list_root:
521 # Not just --list, but --list some-root - do moar work
522 if isinstance(list_root, str):
523 self.list_root = list_root
524 try:
525 sub = self.collection.subcollection_from_path(list_root)
526 self.scoped_collection = sub
527 except KeyError:
528 msg = "Sub-collection '{}' not found!"
529 raise Exit(msg.format(list_root))
530 self.list_tasks()
531 raise Exit
532
533 # Print completion helpers if necessary
534 if self.args.complete.value:
535 complete(
536 names=self.binary_names,
537 core=self.core,
538 initial_context=self.initial_context,
539 collection=self.collection,
540 # NOTE: can't reuse self.parser as it has likely been mutated
541 # between when it was set and now.
542 parser=self._make_parser(),
543 )
544
545 # Fallback behavior if no tasks were given & no default specified
546 # (mostly a subroutine for overriding purposes)
547 # NOTE: when there is a default task, Executor will select it when no

Callers 1

runMethod · 0.95

Calls 9

print_helpMethod · 0.95
print_task_helpMethod · 0.95
list_tasksMethod · 0.95
_make_parserMethod · 0.95
no_tasks_givenMethod · 0.95
completeFunction · 0.90
ParseErrorClass · 0.85
ExitClass · 0.85

Tested by

no test coverage detected