2023-01-02 19:14:16 +01:00
|
|
|
#!/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
|
2023-01-03 16:04:48 +01:00
|
|
|
from argparse import SUPPRESS
|
2023-01-02 19:14:16 +01:00
|
|
|
|
|
|
|
import util
|
|
|
|
from gallery_dl import option
|
|
|
|
|
|
|
|
|
|
|
|
TEMPLATE = """# Command-Line Options
|
|
|
|
|
|
|
|
<!-- auto-generated by {} -->
|
|
|
|
|
2023-01-03 16:04:48 +01:00
|
|
|
{}
|
|
|
|
"""
|
|
|
|
|
|
|
|
TABLE = """
|
|
|
|
## {}
|
|
|
|
|
2023-01-02 19:14:16 +01:00
|
|
|
<table>
|
|
|
|
<tbody valign="top">
|
|
|
|
{}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2023-01-03 16:04:48 +01:00
|
|
|
""".format
|
|
|
|
|
|
|
|
ROW = """<tr>
|
|
|
|
<td>{}</td>
|
2023-01-04 14:41:05 +01:00
|
|
|
<td>{}</td>
|
|
|
|
<td>{}</td>
|
2023-01-03 16:04:48 +01:00
|
|
|
<td>{}</td>
|
|
|
|
</tr>""".format
|
2023-01-02 19:14:16 +01:00
|
|
|
|
|
|
|
|
2023-01-03 16:04:48 +01:00
|
|
|
tables = []
|
2023-01-04 14:41:05 +01:00
|
|
|
sub = re.compile(r"'([^']+)'").sub
|
|
|
|
nb_hyphen = "‑" # non-breaking hyphen
|
2023-01-02 19:14:16 +01:00
|
|
|
|
|
|
|
for group in option.build_parser()._action_groups[2:]:
|
|
|
|
|
2023-01-03 16:04:48 +01:00
|
|
|
tbody = []
|
2023-01-02 19:14:16 +01:00
|
|
|
|
|
|
|
for action in group._group_actions:
|
|
|
|
help = action.help
|
2023-01-03 16:04:48 +01:00
|
|
|
if help == SUPPRESS:
|
2023-01-02 19:14:16 +01:00
|
|
|
continue
|
2023-01-04 14:41:05 +01:00
|
|
|
meta = action.metavar or ""
|
2023-01-02 19:14:16 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
short, long = action.option_strings
|
|
|
|
except ValueError:
|
|
|
|
try:
|
|
|
|
long = action.option_strings[0]
|
|
|
|
except IndexError:
|
|
|
|
continue
|
|
|
|
short = ""
|
|
|
|
|
|
|
|
if short:
|
2023-01-04 14:41:05 +01:00
|
|
|
short = "<code>" + short.replace("-", nb_hyphen) + "</code>"
|
2023-01-02 19:14:16 +01:00
|
|
|
if long:
|
2023-01-04 14:41:05 +01:00
|
|
|
long = "<code>" + long.replace("-", nb_hyphen) + "</code>"
|
|
|
|
if meta:
|
|
|
|
meta = "<code>" + meta.partition("[")[0] + "</code>"
|
2023-01-03 16:04:48 +01:00
|
|
|
if help:
|
|
|
|
help = help.replace("<", "<").replace(">", ">")
|
2023-01-04 14:41:05 +01:00
|
|
|
if "Example: " in help:
|
|
|
|
help, sep, example = help.partition("Example: ")
|
|
|
|
help = sub("<code>\\1</code>", help) + "<br />" + sep + example
|
|
|
|
else:
|
|
|
|
help = sub("<code>\\1</code>", help)
|
2023-01-03 16:04:48 +01:00
|
|
|
|
2023-01-04 14:41:05 +01:00
|
|
|
tbody.append(ROW(short, long, meta, help))
|
2023-01-02 19:14:16 +01:00
|
|
|
|
2023-01-03 16:04:48 +01:00
|
|
|
tables.append(TABLE(group.title, "\n".join(tbody)))
|
2023-01-02 19:14:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
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:]),
|
2023-01-03 16:04:48 +01:00
|
|
|
"\n".join(tables),
|
2023-01-02 19:14:16 +01:00
|
|
|
))
|