MCPcopy Index your code
hub / github.com/hugapi/hug / __call__

Method __call__

hug/interface.py:571–652  ·  view source on GitHub ↗

Calls the wrapped function through the lens of a CLI ran command

(self)

Source from the content-addressed store, hash-verified

569 return self.parser.description or ""
570
571 def __call__(self):
572 """Calls the wrapped function through the lens of a CLI ran command"""
573 context = self.api.context_factory(api=self.api, argparse=self.parser, interface=self)
574
575 def exit_callback(message):
576 self.api.delete_context(context, errors=message)
577
578 self.parser.exit_callback = exit_callback
579
580 self.api._ensure_started()
581 for requirement in self.requires:
582 conclusion = requirement(request=sys.argv, module=self.api.module, context=context)
583 if conclusion and conclusion is not True:
584 self.api.delete_context(context, lacks_requirement=conclusion)
585 return self.output(conclusion, context)
586
587 if self.interface.is_method:
588 self.parser.prog = "%s %s" % (self.api.module.__name__, self.interface.name)
589
590 known, unknown = self.parser.parse_known_args()
591 pass_to_function = vars(known)
592 for option, directive in self.directives.items():
593 arguments = (self.defaults[option],) if option in self.defaults else ()
594 pass_to_function[option] = directive(
595 *arguments, api=self.api, argparse=self.parser, context=context, interface=self
596 )
597
598 for field, type_handler in self.reaffirm_types.items():
599 if field in pass_to_function:
600 if not pass_to_function[field] and type_handler in (
601 list,
602 tuple,
603 hug.types.Multiple,
604 ):
605 pass_to_function[field] = type_handler(())
606 else:
607 pass_to_function[field] = self.initialize_handler(
608 type_handler, pass_to_function[field], context=context
609 )
610
611 if getattr(self, "validate_function", False):
612 errors = self.validate_function(pass_to_function)
613 if errors:
614 self.api.delete_context(context, errors=errors)
615 return self.output(errors, context)
616
617 args = None
618 if self.additional_options:
619 args = []
620 for parameter in self.interface.parameters:
621 if parameter in pass_to_function:
622 args.append(pass_to_function.pop(parameter))
623 args.extend(pass_to_function.pop(self.additional_options, ()))
624 if self.interface.takes_kwargs:
625 add_options_to = None
626 for option in unknown:
627 if option.startswith("--"):
628 if add_options_to:

Callers

nothing calls this directly

Calls 10

outputMethod · 0.95
requirementFunction · 0.85
directiveFunction · 0.85
context_factoryMethod · 0.80
_ensure_startedMethod · 0.80
initialize_handlerMethod · 0.80
_rewrite_paramsMethod · 0.80
cleanup_parametersMethod · 0.80
delete_contextMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected