def run(self):
        print('generating usage docs')
        # allows us to build docs without the C modules fully loaded during help generation
        from borg.archiver import Archiver
        parser = Archiver().build_parser(prog='borg')
        choices = {}
        for action in parser._actions:
            if action.choices is not None:
                choices.update(action.choices)
        print('found commands: %s' % list(choices.keys()))
        if not os.path.exists('docs/usage'):
            os.mkdir('docs/usage')
        for command, parser in choices.items():
            print('generating help for %s' % command)
            with open('docs/usage/%s.rst.inc' % command, 'w') as doc:
                if command == 'help':
                    for topic in Archiver.helptext:
                        params = {"topic": topic,
                                  "underline": '~' * len('borg help ' + topic)}
                        doc.write(".. _borg_{topic}:\n\n".format(**params))
                        doc.write("borg help {topic}\n{underline}\n::\n\n".format(**params))
                        doc.write(Archiver.helptext[topic])
                else:
                    params = {"command": command,
                              "underline": '-' * len('borg ' + command)}
                    doc.write(".. _borg_{command}:\n\n".format(**params))
                    doc.write("borg {command}\n{underline}\n::\n\n    borg {command}".format(**params))
                    self.write_usage(parser, doc)
                    epilog = parser.epilog
                    parser.epilog = None
                    self.write_options(parser, doc)
                    doc.write("\n\nDescription\n~~~~~~~~~~~\n")
                    doc.write(epilog)
        common_options = [group for group in choices['create']._action_groups if group.title == 'Common options'][0]
        with open('docs/usage/common-options.rst.inc', 'w') as doc:
            self.write_options_group(common_options, doc, False)
dataset/ETHPy150Open borgbackup/borg/setup.py/build_usage.run/original