Esempio n. 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
Esempio n. 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
Esempio n. 3
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()
Esempio n. 4
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()
Esempio n. 5
0
def RenderMarkdown(fin, width, height=HELP_WINDOW_HEIGHT, compact=True):
    """Renders the markdown for the help prompt in the gcloud shell.

  Args:
    fin: the input stream containing the markdown.
    width: the width for which to create the renderer.
    height: optional value representing the height for which to create the
    renderer. Defaults to HELP_WINDOW_HEIGHT.
    compact: optional value representing whether the renderer representation
    should be compact. Defaults to True.

  Returns:
    A MarkdownRenderer Finish() value.
  """
    return render_document.MarkdownRenderer(token_renderer.TokenRenderer(
        width=width, height=height, compact=compact),
                                            fin=fin).Run()