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

Function HelpText

fire/helptext.py:50–94  ·  view source on GitHub ↗

Gets the help string for the current component, suitable for a help screen. Args: component: The component to construct the help string for. trace: The Fire trace of the command so far. The command executed so far can be extracted from this trace. verbose: Whether to include pri

(component, trace=None, verbose=False)

Source from the content-addressed store, hash-verified

48
49
50def HelpText(component, trace=None, verbose=False):
51 """Gets the help string for the current component, suitable for a help screen.
52
53 Args:
54 component: The component to construct the help string for.
55 trace: The Fire trace of the command so far. The command executed so far
56 can be extracted from this trace.
57 verbose: Whether to include private members in the help screen.
58
59 Returns:
60 The full help screen as a string.
61 """
62 # Preprocessing needed to create the sections:
63 info = inspectutils.Info(component)
64 actions_grouped_by_kind = _GetActionsGroupedByKind(component, verbose=verbose)
65 spec = inspectutils.GetFullArgSpec(component)
66 metadata = decorators.GetMetadata(component)
67
68 # Sections:
69 name_section = _NameSection(component, info, trace=trace, verbose=verbose)
70 synopsis_section = _SynopsisSection(
71 component, actions_grouped_by_kind, spec, metadata, trace=trace)
72 description_section = _DescriptionSection(component, info)
73 # TODO(dbieber): Add returns and raises sections for functions.
74
75 if callable(component):
76 args_and_flags_sections, notes_sections = _ArgsAndFlagsSections(
77 info, spec, metadata)
78 else:
79 args_and_flags_sections = []
80 notes_sections = []
81 usage_details_sections = _UsageDetailsSections(component,
82 actions_grouped_by_kind)
83
84 sections = (
85 [name_section, synopsis_section, description_section]
86 + args_and_flags_sections
87 + usage_details_sections
88 + notes_sections
89 )
90 valid_sections = [section for section in sections if section is not None]
91 return '\n\n'.join(
92 _CreateOutputSection(name, content)
93 for name, content in valid_sections
94 )
95
96
97def _NameSection(component, info, trace=None, verbose=False) -> tuple[str, str]:

Callers

nothing calls this directly

Calls 7

_GetActionsGroupedByKindFunction · 0.85
_NameSectionFunction · 0.85
_SynopsisSectionFunction · 0.85
_DescriptionSectionFunction · 0.85
_ArgsAndFlagsSectionsFunction · 0.85
_UsageDetailsSectionsFunction · 0.85
_CreateOutputSectionFunction · 0.85

Tested by

no test coverage detected