def run(self):
        is_recursive = not 'no-recursive' in self.options
        order_by = self.options.get('order_by', 'name')
        is_reverse = 'reverse' in self.options
        max_count = self.options.get('count', None)
        pattern = self.options.get('pattern', None)
        show_hidden = 'show-hidden' in self.options
        title_only = 'title-only' in self.options

        ctx = self.state.document.settings.ctx

        obj = self.state.document.settings.obj
        if isinstance(obj, TreeObject):
            tree = obj
        else:
            tree = obj.parent

        if self.arguments:
            path = self.arguments[0]

            try:
                if path.startswith('/'):
                    tree = obj.commit.tree[path]

                else:
                    tree = tree[path]
            except __HOLE__, e:
                error = self.state_machine.reporter.error(
                    'directory not found "%s"' % path,
                    nodes.literal_block(self.block_text, self.block_text),
                    line=self.lineno
                )
                return [error]

        if order_by == 'name':
            key_func = lambda x: x.name

        elif order_by == 'last_modified':
            key_func = lambda x: x.last_modified

        count = 0
        result = []

        for root, dirs, files in tree.walk():
            files.sort(key=key_func, reverse=is_reverse)
            for f in files:
                if f.name.startswith('.') and not show_hidden:
                    # skip hidden file
                    continue

                if pattern is not None and not fnmatch.fnmatch(f.name, pattern):
                    continue

                count += 1
                doc = blikit.render.render_blob(ctx, f)

                if title_only:
                    template = 'innertitle.html'
                else:
                    template = 'innerdoc.html'

                html = ctx.render_template(template, doc=doc, blob=f,
                                           commit=f.commit, context=ctx)
                result.append(nodes.raw('', html, format='html'))

                if max_count is not None and count >= max_count:
                    # break inner loop
                    break

            if max_count is not None and count >= max_count:
                # break outer loop
                break

            if not is_recursive:
                break

            if not show_hidden:
                # remove hidden dirs
                dirs[:] = filter(lambda d: not d.name.startswith('.'), dirs)

            dirs.sort(key=key_func, reverse=is_reverse)

        return result
dataset/ETHPy150Open nakamuray/blikit/blikit/docutilsext.py/ShowContents.run