#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2023 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. """Generate a Markdown document listing gallery-dl's command-line arguments""" import os import re from argparse import SUPPRESS import util from gallery_dl import option TEMPLATE = """# Command-Line Options {} """ TABLE = """ ## {} {}
""".format ROW = """ {} {} {} """.format sub = re.compile(r"'([^']+)'").sub tables = [] for group in option.build_parser()._action_groups[2:]: tbody = [] append = tbody.append width = ' width="28%"' for action in group._group_actions: help = action.help if help == SUPPRESS: continue try: short, long = action.option_strings except ValueError: try: long = action.option_strings[0] except IndexError: continue short = "" if short: short = "" + short + "" if long: long = '' + long + "" if help: help = help.replace("<", "<").replace(">", ">") help = sub("\\1", help) append(ROW(short, width, long, help)) width = "" tables.append(TABLE(group.title, "\n".join(tbody))) with open(util.path("docs", "options.md"), "w", encoding="utf-8") as fp: fp.write(TEMPLATE.format( "/".join(os.path.normpath(__file__).split(os.sep)[-2:]), "\n".join(tables), ))