Beispiel #1
0
def _CreateArgItem(arg, docstring_info, spec):
  """Returns a string describing a positional argument.

  Args:
    arg: The name of the positional argument.
    docstring_info: A docstrings.DocstringInfo namedtuple with information about
      the containing function's docstring.
    spec: An instance of fire.inspectutils.FullArgSpec, containing type and
     default information about the arguments to a callable.

  Returns:
    A string to be used in constructing the help screen for the function.
  """

  # The help string is indented, so calculate the maximum permitted length
  # before indentation to avoid exceeding the maximum line length.
  max_str_length = LINE_LENGTH - SECTION_INDENTATION - SUBSECTION_INDENTATION

  description = _GetArgDescription(arg, docstring_info)

  arg_string = formatting.BoldUnderline(arg.upper())

  arg_type = _GetArgType(arg, spec)
  arg_type = 'Type: {}'.format(arg_type) if arg_type else ''
  available_space = max_str_length - len(arg_type)
  arg_type = (
      formatting.EllipsisTruncate(arg_type, available_space, max_str_length))

  description = '\n'.join(part for part in (arg_type, description) if part)

  return _CreateItem(arg_string, description, indent=SUBSECTION_INDENTATION)
Beispiel #2
0
 def testHelpTextBoldCommandName(self):
     component = tc.ClassWithDocstring()
     t = trace.FireTrace(component, name='ClassWithDocstring')
     help_screen = helptext.HelpText(component, t)
     self.assertIn(
         formatting.Bold('NAME') + '\n    ClassWithDocstring', help_screen)
     self.assertIn(formatting.Bold('COMMANDS') + '\n', help_screen)
     self.assertIn(
         formatting.BoldUnderline('COMMAND') +
         ' is one of the following:\n', help_screen)
     self.assertIn(formatting.Bold('print_msg') + '\n', help_screen)
Beispiel #3
0
 def testHelpTextBoldCommandName(self):
     component = tc.ClassWithDocstring()
     t = trace.FireTrace(component, name="ClassWithDocstring")
     help_screen = helptext.HelpText(component, t)
     self.assertIn(formatting.Bold("NAME") + "\n    ClassWithDocstring", help_screen)
     self.assertIn(formatting.Bold("COMMANDS") + "\n", help_screen)
     self.assertIn(
         formatting.BoldUnderline("COMMAND") + " is one of the following:\n",
         help_screen,
     )
     self.assertIn(formatting.Bold("print_msg") + "\n", help_screen)
Beispiel #4
0
def _CreatePositionalArgItem(arg, docstring_info):
  """Returns a string describing a positional argument.

  Args:
    arg: The name of the positional argument.
    docstring_info: A docstrings.DocstringInfo namedtuple with information about
      the containing function's docstring.
  Returns:
    A string to be used in constructing the help screen for the function.
  """
  description = None
  if docstring_info.args:
    for arg_in_docstring in docstring_info.args:
      if arg_in_docstring.name == arg:
        description = arg_in_docstring.description

  arg = arg.upper()
  if description:
    return _CreateItem(formatting.BoldUnderline(arg), description, indent=4)
  else:
    return formatting.BoldUnderline(arg)
Beispiel #5
0
def _CreateArgItem(arg, docstring_info):
  """Returns a string describing a positional argument.

  Args:
    arg: The name of the positional argument.
    docstring_info: A docstrings.DocstringInfo namedtuple with information about
      the containing function's docstring.
  Returns:
    A string to be used in constructing the help screen for the function.
  """
  description = _GetArgDescription(arg, docstring_info)

  arg = arg.upper()
  return _CreateItem(formatting.BoldUnderline(arg), description, indent=4)