A list of elements that comprise the usage summary for a callable.
(spec, metadata)
| 701 | |
| 702 | |
| 703 | def _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 | |
| 727 | def _KeywordOnlyArguments(spec, required=True): |