The list of availability lines for a callable for use in a usage string.
(spec)
| 730 | |
| 731 | |
| 732 | def _GetCallableAvailabilityLines(spec): |
| 733 | """The list of availability lines for a callable for use in a usage string.""" |
| 734 | args_with_defaults = spec.args[len(spec.args) - len(spec.defaults):] |
| 735 | |
| 736 | # TODO(dbieber): Handle args_with_no_defaults if not accepts_positional_args. |
| 737 | optional_flags = [f'--{flag}' for flag in itertools.chain( |
| 738 | args_with_defaults, _KeywordOnlyArguments(spec, required=False))] |
| 739 | required_flags = [ |
| 740 | f'--{flag}' for flag in _KeywordOnlyArguments(spec, required=True) |
| 741 | ] |
| 742 | |
| 743 | # Flags section: |
| 744 | availability_lines = [] |
| 745 | if optional_flags: |
| 746 | availability_lines.append( |
| 747 | _CreateAvailabilityLine(header='optional flags:', items=optional_flags, |
| 748 | header_indent=2)) |
| 749 | if required_flags: |
| 750 | availability_lines.append( |
| 751 | _CreateAvailabilityLine(header='required flags:', items=required_flags, |
| 752 | header_indent=2)) |
| 753 | if spec.varkw: |
| 754 | additional_flags = ('additional flags are accepted' |
| 755 | if optional_flags or required_flags else |
| 756 | 'flags are accepted') |
| 757 | availability_lines.append( |
| 758 | _CreateAvailabilityLine(header=additional_flags, items=[], |
| 759 | header_indent=2)) |
| 760 | return availability_lines |
| 761 | |
| 762 | |
| 763 | def _CreateAvailabilityLine(header, items, |
no test coverage detected