Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def HelpString(component, trace=None, verbose=False):
"""Returns a help string for a supplied component.
The component can be any Python class, object, function, module, etc.
Args:
component: The component to determine the help string for.
trace: The Fire trace leading to this component.
verbose: Whether to include private members in the help string.
Returns:
String suitable for display giving information about the component.
"""
info = inspectutils.Info(component)
info['usage'] = UsageString(component, trace, verbose)
info['docstring_info'] = docstrings.parse(info['docstring'])
return _HelpText(info, trace)
def _ValuesUsageDetailsSection(component, values):
"""Creates a section tuple for the values section of the usage details."""
value_item_strings = []
for value_name, value in values.GetItems():
del value
init_info = inspectutils.Info(component.__class__.__init__)
value_item = None
if 'docstring_info' in init_info:
init_docstring_info = init_info['docstring_info']
if init_docstring_info.args:
for arg_info in init_docstring_info.args:
if arg_info.name == value_name:
value_item = _CreateItem(value_name, arg_info.description)
if value_item is None:
value_item = str(value_name)
value_item_strings.append(value_item)
return ('VALUES', _NewChoicesSection('VALUE', value_item_strings))
def HelpText(component, trace=None, verbose=False):
"""Gets the help string for the current component, suitalbe 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 private members in the help screen.
Returns:
The full help screen as a string.
"""
# Preprocessing needed to create the sections:
info = inspectutils.Info(component)
actions_grouped_by_kind = _GetActionsGroupedByKind(component, verbose=verbose)
spec = inspectutils.GetFullArgSpec(component)
metadata = decorators.GetMetadata(component)
# Sections:
name_section = _NameSection(component, info, trace=trace, verbose=verbose)
synopsis_section = _SynopsisSection(
component, actions_grouped_by_kind, spec, metadata, trace=trace)
description_section = _DescriptionSection(component, info)
# TODO(dbieber): Add returns and raises sections for functions.
if callable(component):
args_and_flags_sections, notes_sections = _ArgsAndFlagsSections(
info, spec, metadata)
else:
args_and_flags_sections = []
def _MakeUsageDetailsSection(action_group):
"""Creates a usage details section for the provided action group."""
item_strings = []
for name, member in action_group.GetItems():
info = inspectutils.Info(member)
item = name
docstring_info = info.get('docstring_info')
if (docstring_info
and not custom_descriptions.NeedsCustomDescription(member)):
summary = docstring_info.summary
else:
summary = None
item = _CreateItem(name, summary)
item_strings.append(item)
return (action_group.plural.upper(),
_NewChoicesSection(action_group.name.upper(), item_strings))