code: def _runcog(options, files, uncog=False):
      
      options.order('cog', 'sphinx', add_rest=True)
      c = Cog()
      if uncog:
          c.options.bNoGenerate = True
      c.options.bReplace = True
      c.options.bDeleteCode = options.get("delete_code", False)
      includedir = options.get('includedir', None)
      if includedir:
          include = Includer(includedir, cog=c,
                             include_markers=options.get("include_markers"))
          # load cog's namespace with our convenience functions.
          c.options.defines['include'] = include
          c.options.defines['sh'] = _cogsh(c)
  
      c.options.sBeginSpec = options.get('beginspec', '[[[cog')
      c.options.sEndSpec = options.get('endspec', ']]]')
      c.options.sEndOutput = options.get('endoutput', '[[[end]]]')
  
      basedir = options.get('basedir', None)
      if basedir is None:
          basedir = (path(options.get('docroot', "docs"))
                     / options.get('sourcedir', ""))
      basedir = path(basedir)
  
      if not files:
          pattern = options.get("pattern", "*.rst")
          if pattern:
              files = basedir.walkfiles(pattern)
          else:
              files = basedir.walkfiles()
      for f in sorted(files):
          dry("cog %s" % f, c.processOneFile, f)
docs: Common function for the cog and runcog tasks.