You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gallery-dl/scripts/options.py

78 lines
1.7 KiB

#!/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
import util
from gallery_dl import option
TEMPLATE = """# Command-Line Options
<!-- auto-generated by {} -->
<table>
<thead>
<tr>
<th></th>
<th width="26%"></th>
<th></th>
</tr>
</thead>
<tbody valign="top">
{}
</tbody>
</table>
"""
tbody = []
append = tbody.append
sub = re.compile(r"'([^']+)'").sub
for group in option.build_parser()._action_groups[2:]:
append('\n<tr>\n <td colspan="3"><strong>' +
group.title + '</strong></td>\n</tr>')
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 = "<code>" + short + "</code>"
if long:
long = '<code>' + long + "</code>"
append("<tr>")
append(" <td>" + short + "</td>")
append(" <td>" + long + "</td>")
append(" <td>" + sub("<code>\\1</code>", help) + "</td>")
append("</tr>")
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(tbody),
))