MCPcopy
hub / github.com/google/python-fire / _GetCallableUsageItems

Function _GetCallableUsageItems

fire/helptext.py:703–724  ·  view source on GitHub ↗

A list of elements that comprise the usage summary for a callable.

(spec, metadata)

Source from the content-addressed store, hash-verified

701
702
703def _GetCallableUsageItems(spec, metadata):
704 """A list of elements that comprise the usage summary for a callable."""
705 args_with_no_defaults = spec.args[:len(spec.args) - len(spec.defaults)]
706 args_with_defaults = spec.args[len(spec.args) - len(spec.defaults):]
707
708 # Check if positional args are allowed. If not, show flag syntax for args.
709 accepts_positional_args = metadata.get(decorators.ACCEPTS_POSITIONAL_ARGS)
710
711 if not accepts_positional_args:
712 items = [f'--{arg}={arg.upper()}'
713 for arg in args_with_no_defaults]
714 else:
715 items = [arg.upper() for arg in args_with_no_defaults]
716
717 # If there are any arguments that are treated as flags:
718 if args_with_defaults or spec.kwonlyargs or spec.varkw:
719 items.append('<flags>')
720
721 if spec.varargs:
722 items.append(f'[{spec.varargs.upper()}]...')
723
724 return items
725
726
727def _KeywordOnlyArguments(spec, required=True):

Callers 1

UsageTextFunction · 0.85

Calls 1

upperMethod · 0.80

Tested by

no test coverage detected