Returns usage text for the given component. Args: component: The component to determine the usage text for. trace: The Fire trace object containing all metadata of current execution. verbose: Whether to display the usage text in verbose mode. Returns: String suitable for displa
(component, trace=None, verbose=False)
| 622 | |
| 623 | |
| 624 | def UsageText(component, trace=None, verbose=False): |
| 625 | """Returns usage text for the given component. |
| 626 | |
| 627 | Args: |
| 628 | component: The component to determine the usage text for. |
| 629 | trace: The Fire trace object containing all metadata of current execution. |
| 630 | verbose: Whether to display the usage text in verbose mode. |
| 631 | |
| 632 | Returns: |
| 633 | String suitable for display in an error screen. |
| 634 | """ |
| 635 | # Get the command so far: |
| 636 | if trace: |
| 637 | command = trace.GetCommand() |
| 638 | needs_separating_hyphen_hyphen = trace.NeedsSeparatingHyphenHyphen() |
| 639 | else: |
| 640 | command = None |
| 641 | needs_separating_hyphen_hyphen = False |
| 642 | |
| 643 | if not command: |
| 644 | command = '' |
| 645 | |
| 646 | # Build the continuations for the command: |
| 647 | continued_command = command |
| 648 | |
| 649 | spec = inspectutils.GetFullArgSpec(component) |
| 650 | metadata = decorators.GetMetadata(component) |
| 651 | |
| 652 | # Usage for objects. |
| 653 | actions_grouped_by_kind = _GetActionsGroupedByKind(component, verbose=verbose) |
| 654 | possible_actions = _GetPossibleActions(actions_grouped_by_kind) |
| 655 | |
| 656 | continuations = [] |
| 657 | if possible_actions: |
| 658 | continuations.append(_GetPossibleActionsUsageString(possible_actions)) |
| 659 | |
| 660 | availability_lines = _UsageAvailabilityLines(actions_grouped_by_kind) |
| 661 | |
| 662 | if callable(component): |
| 663 | callable_items = _GetCallableUsageItems(spec, metadata) |
| 664 | if callable_items: |
| 665 | continuations.append(' '.join(callable_items)) |
| 666 | elif trace: |
| 667 | continuations.append(trace.separator) |
| 668 | availability_lines.extend(_GetCallableAvailabilityLines(spec)) |
| 669 | |
| 670 | if continuations: |
| 671 | continued_command += ' ' + ' | '.join(continuations) |
| 672 | help_command = ( |
| 673 | command |
| 674 | + (' -- ' if needs_separating_hyphen_hyphen else ' ') |
| 675 | + '--help' |
| 676 | ) |
| 677 | |
| 678 | return f"""Usage: {continued_command} |
| 679 | {''.join(availability_lines)} |
| 680 | For detailed information on this command, run: |
| 681 | {help_command}""" |
nothing calls this directly
no test coverage detected