def _DescriptionSection(component, info): """The "Description" sections of the help string. Args: component: The component to produce the description section for. info: The info dict for the component of interest. Returns: Returns the description if available. If not, returns the summary. If neither are available, returns None. """ if custom_descriptions.NeedsCustomDescription(component): available_space = LINE_LENGTH - SECTION_INDENTATION description = custom_descriptions.GetDescription(component, available_space, LINE_LENGTH) summary = custom_descriptions.GetSummary(component, available_space, LINE_LENGTH) else: description = _GetDescription(info) summary = _GetSummary(info) # Fall back to summary if description is not available. text = description or summary or None if text: return ('DESCRIPTION', text) else: return None
def _NameSection(component, info, trace=None, verbose=False): """The "Name" section of the help string.""" # Only include separators in the name in verbose mode. current_command = _GetCurrentCommand(trace, include_separators=verbose) summary = _GetSummary(info) # If the docstring is one of the messy builtin docstrings, show custom one. if custom_descriptions.NeedsCustomDescription(component): available_space = LINE_LENGTH - SECTION_INDENTATION - len(current_command + ' - ') summary = custom_descriptions.GetSummary(component, available_space, LINE_LENGTH) if summary: text = current_command + ' - ' + summary else: text = current_command return ('NAME', text)
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 elif custom_descriptions.NeedsCustomDescription(member): summary = custom_descriptions.GetSummary( member, LINE_LENGTH - SECTION_INDENTATION, LINE_LENGTH) else: summary = None item = _CreateItem(name, summary) item_strings.append(item) return (action_group.plural.upper(), _NewChoicesSection(action_group.name.upper(), item_strings))
def test_string_type_summary_not_enough_space_long_truncated(self): component = 'Lorem ipsum dolor sit amet' summary = custom_descriptions.GetSummary( obj=component, available_space=10, line_length=LINE_LENGTH) self.assertEqual(summary, '"Lorem..."')
def test_string_type_summary_not_enough_space_new_line(self): component = 'Test' summary = custom_descriptions.GetSummary( obj=component, available_space=4, line_length=LINE_LENGTH) self.assertEqual(summary, '"Test"')
def test_string_type_summary_not_enough_space_truncated(self): component = "Test" summary = custom_descriptions.GetSummary( obj=component, available_space=5, line_length=LINE_LENGTH ) self.assertEqual(summary, '"..."')