コード例 #1
0
def GenerateHelpForCommand(cli, token, width):
  """Returns help lines for a command token."""
  lines = []

  # Get description
  height = 4
  gen = markdown.CliTreeMarkdownGenerator(token.tree, cli.root)
  gen.PrintSectionIfExists('DESCRIPTION', disable_header=True)
  doc = gen.Edit()
  fin = StringIO.StringIO(doc)
  lines.extend(render_document.MarkdownRenderer(
      token_renderer.TokenRenderer(
          width=width, height=height), fin=fin).Run())

  lines.append([])  # blank line

  # Get synopis
  height = 5
  gen = markdown.CliTreeMarkdownGenerator(token.tree, cli.root)
  gen.PrintSynopsisSection()
  doc = gen.Edit()
  fin = StringIO.StringIO(doc)
  lines.extend(render_document.MarkdownRenderer(
      token_renderer.TokenRenderer(
          width=width, height=height, compact=False), fin=fin).Run())

  return lines
コード例 #2
0
def GenerateHelpForCommand(token, width):
    lines = []

    # Get description
    height = 2
    gen = markdown.CliTreeMarkdownGenerator(token.tree, gcloud_tree)
    gen.PrintSectionIfExists('DESCRIPTION', disable_header=True)
    doc = gen.Edit()
    fin = StringIO.StringIO(doc)
    lines.extend(
        render_document.MarkdownRenderer(token_renderer.TokenRenderer(
            width=width, height=height),
                                         fin=fin).Run())

    lines.append([])  # blank line

    # Get synopis
    gen = markdown.CliTreeMarkdownGenerator(token.tree, gcloud_tree)
    gen.PrintSynopsisSection()
    doc = gen.Edit()
    fin = StringIO.StringIO(doc)
    lines.extend(
        render_document.MarkdownRenderer(token_renderer.TokenRenderer(
            width=width, height=5, compact=False),
                                         fin=fin).Run())

    lines.append([])  # blank line

    lines.append([(Token.Purple, 'ctrl-w'),
                  (Token, ' to open full reference page within browser')])

    return lines
コード例 #3
0
    def testRootCommandMarkdown(self):
        md = cli_tree_markdown.CliTreeMarkdownGenerator(self.ROOT,
                                                        self.ROOT).Generate()
        expected = """\
# (1)


## NAME

 - root command with empty path


## SYNOPSIS

`` _COMMAND_


## DESCRIPTION

The gcloud shell.


## COMMANDS

`_COMMAND_` is one of the following:

*link:exit[exit]*::

Exit the shell.
"""
        self.assertEqual(expected, md)
コード例 #4
0
def GenerateHelpForPositional(token, width):
    gen = markdown.CliTreeMarkdownGenerator(gcloud_tree, gcloud_tree)
    gen.PrintPositionalDefinition(markdown.Positional(token.tree))
    mark = gen.Edit()

    fin = StringIO.StringIO(mark)
    return render_document.MarkdownRenderer(token_renderer.TokenRenderer(
        width=width, height=HELP_WINDOW_HEIGHT),
                                            fin=fin).Run()
コード例 #5
0
def GenerateHelpForFlag(cli, token, width):
  """Returns help lines for a flag token."""
  gen = markdown.CliTreeMarkdownGenerator(cli.root, cli.root)
  gen.PrintFlagDefinition(token.tree)
  mark = gen.Edit()

  fin = StringIO.StringIO(mark)
  return render_document.MarkdownRenderer(
      token_renderer.TokenRenderer(
          width=width, height=cli.config.help_lines), fin=fin).Run()
コード例 #6
0
def GetDefinitionForPositional(token):
    """Gets the definition for the positional specified in token.

  Args:
    token: the ArgTokenType.POSITIONAL token for which to get the definition.

  Returns:
    A StringIO with the definition of the token.
  """
    gen = markdown.CliTreeMarkdownGenerator(gcloud_tree, gcloud_tree)
    gen.PrintPositionalDefinition(markdown.Positional(token.tree))
    mark = gen.Edit()
    return StringIO.StringIO(mark)
コード例 #7
0
def GetDefinitionForFlag(token):
    """Gets the definition for the flag specified in token.

  Args:
    token: the ArgTokenType.FLAG/FLAG_ARG token for which to get the definition.

  Returns:
    A StringIO with the definition of the token.
  """
    gen = markdown.CliTreeMarkdownGenerator(gcloud_tree, gcloud_tree)
    gen.PrintFlagDefinition(token.tree)
    mark = gen.Edit()
    return StringIO.StringIO(mark)
コード例 #8
0
def GetSynopsisForCommand(token):
    """Gets the synopsis for the command specified in token.

  Args:
    token: the ArgTokenType.COMMAND token for which to get the synopsis.

  Returns:
    A StringIO with the synopsis of the token.
  """
    gen = markdown.CliTreeMarkdownGenerator(token.tree, gcloud_tree)
    gen.PrintSynopsisSection()
    doc = gen.Edit()
    return StringIO.StringIO(doc)
コード例 #9
0
def GetDescriptionForCommand(token):
    """Gets the description for the command specified in token.

  Args:
    token: the ArgTokenType.COMMAND token for which to get the description.

  Returns:
    A StringIO with the description of the token.
  """
    gen = markdown.CliTreeMarkdownGenerator(token.tree, gcloud_tree)
    gen.PrintSectionIfExists('DESCRIPTION', disable_header=True)
    doc = gen.Edit()
    return StringIO.StringIO(doc)