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
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
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)
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()
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()
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)
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)
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)
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)