def __call__(self, parser, namespace, values, option_string=None): markdown.Markdown(command, sys.stdout.write) sys.exit(0)
def Visit(self, node, parent, is_group): """Renders a help text doc for each node in the CLI tree. Args: node: group/command CommandCommon info. parent: The parent Visit() return value, None at the top level. is_group: True if node is a group, otherwise its is a command. Returns: The parent value, ignored here. """ # Set up the destination dir for this level. command = node.GetPath() if is_group: directory = os.path.join(self._directory, *command[1:]) files.MakeDir(directory, mode=0755) else: directory = os.path.join(self._directory, *command[1:-1]) # Render the help text document. path = os.path.join(directory, 'GROUP' if is_group else command[-1]) with open(path, 'w') as f: md = markdown.Markdown(node) render_document.RenderDocument(style='text', fin=cStringIO.StringIO(md), out=f) return parent
def Visit(self, node, parent, is_group): """Renders document file for each node in the CLI tree. Args: node: group/command CommandCommon info. parent: The parent Visit() return value, None at the top level. is_group: True if node is a group, otherwise its is a command. Returns: The parent value, ignored here. """ if self._style == 'linter': meta_data = actions.GetCommandMetaData(node) else: meta_data = None command = node.GetPath() path = os.path.join(self._directory, '_'.join(command)) + self._suffix with files.FileWriter(path) as f: md = markdown.Markdown(node) render_document.RenderDocument(style=self._style, title=' '.join(command), fin=io.StringIO(md), out=f, command_metadata=meta_data) return parent
def __call__(self, parser, namespace, values, option_string=None): """Render a help document according to the style in values. Args: parser: The ArgParse object. namespace: The ArgParse namespace. values: The --document flag ArgDict() value: style=STYLE The output style. Must be specified. title=DOCUMENT TITLE The document title. notes=SENTENCES Inserts SENTENCES into the document NOTES section. option_string: The ArgParse flag string. Raises: parser_errors.ArgumentError: For unknown flag value attribute name. """ base.LogCommand(parser.prog, namespace) if default_style: # --help metrics.Loaded() style = default_style notes = None title = None for attributes in values: for name, value in six.iteritems(attributes): if name == 'notes': notes = value elif name == 'style': style = value elif name == 'title': title = value else: raise parser_errors.ArgumentError( 'Unknown document attribute [{0}]'.format(name)) if title is None: title = command.dotted_name metrics.Help(command.dotted_name, style) # '--help' is set by the --help flag, the others by gcloud <style> ... . if style in ('--help', 'help', 'topic'): style = 'text' md = io.StringIO(markdown.Markdown(command)) out = (io.StringIO() if console_io.IsInteractive(output=True) else None) if style == 'linter': meta_data = GetCommandMetaData(command) else: meta_data = None render_document.RenderDocument(style, md, out=out or log.out, notes=notes, title=title, command_metadata=meta_data) metrics.Ran() if out: console_io.More(out.getvalue()) sys.exit(0)
def __call__(self, parser, namespace, values, option_string=None): command.LoadAllSubElements() markdown.Markdown(command, sys.stdout.write) sys.exit(0)
def __call__(self, parser, namespace, values, option_string=None): """Render a help document according to the style in values. Args: parser: The ArgParse object. namespace: The ArgParse namespace. values: The --document flag ArgDict() value: style=STYLE The output style. Must be specified. title=DOCUMENT TITLE The document title. notes=SENTENCES Inserts SENTENCES into the document NOTES section. option_string: The ArgParse flag string. Raises: ArgumentTypeError: For unknown flag value attribute name. """ if default_style: # --help metrics.Loaded() style = default_style notes = None title = None for attributes in values: for name, value in attributes.iteritems(): if name == 'notes': notes = value elif name == 'style': style = value elif name == 'title': title = value else: raise argparse.ArgumentTypeError( 'Unknown document attribute [{}]'.format(name)) if title is None: title = command.dotted_name metrics.Help(command.dotted_name, style) # 'help' is set by the help command, '--help' by the --help flag. if style in ('--help', 'help'): style = 'text' md = cStringIO.StringIO(markdown.Markdown(command)) out = (cStringIO.StringIO() if console_io.IsInteractive( output=True) else None) render_document.RenderDocument(style, md, out=out, notes=notes, title=title) metrics.Ran() if out: console_io.More(out.getvalue()) sys.exit(0)
def Visit(self, node, parent, is_group): """Renders a manpage doc for each node in the CLI tree. Args: node: group/command CommandCommon info. parent: The parent Visit() return value, None at the top level. is_group: True if node is a group, otherwise its is a command. Returns: The parent value, ignored here. """ command = node.GetPath() path = os.path.join(self._directory, '_'.join(command)) + '.1' with open(path, 'w') as f: md = markdown.Markdown(node) render_document.RenderDocument(style='man', title=' '.join(command), fin=cStringIO.StringIO(md), out=f) return parent
def Visit(self, node, parent, is_group): """Updates the TOC and Renders a DevSite doc for each node in the CLI tree. Args: node: group/command CommandCommon info. parent: The parent Visit() return value, None at the top level. is_group: True if node is a group, otherwise its is a command. Returns: The parent value, ignored here. """ def _UpdateTOC(): """Updates the DevSIte TOC.""" depth = len(command) - 1 if not depth: return if depth == 1: if self._toc_main: # Close the current main group toc if needed. self._toc_main.close() # Create a new main group toc. toc_path = os.path.join(directory, self._TOC) toc = open(toc_path, 'w') self._toc_main = toc title = ' '.join(command) toc.write('toc:\n') toc.write('- title: "%s"\n' % title) toc.write(' path: %s\n' % '/'.join([self._REFERENCE] + command[1:])) toc.write(' section:\n') toc = self._toc_root indent = ' ' if is_group: toc.write('%s- include: %s\n' % (indent, '/'.join([self._REFERENCE] + command[1:] + [self._TOC]))) return else: toc = self._toc_main indent = ' ' * (depth - 1) title = command[-1] toc.write('%s- title: "%s"\n' % (indent, title)) toc.write('%s path: %s\n' % (indent, '/'.join([self._REFERENCE] + command[1:]))) if is_group: toc.write('%s section:\n' % indent) # Set up the destination dir for this level. command = node.GetPath() if is_group: directory = os.path.join(self._directory, *command[1:]) files.MakeDir(directory, mode=0755) else: directory = os.path.join(self._directory, *command[1:-1]) # Render the DevSite document. path = os.path.join(directory, 'index' if is_group else command[-1]) + '.html' with open(path, 'w') as f: md = markdown.Markdown(node) render_document.RenderDocument(style='devsite', title=' '.join(command), fin=cStringIO.StringIO(md), out=f) _UpdateTOC() return parent