forked from mikf/gallery-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.py
executable file
·42 lines (28 loc) · 977 Bytes
/
options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/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 document listing gallery-dl's command-line arguments"""
import os
import re
import sys
import util
from gallery_dl import option
TEMPLATE = """# Command-Line Options
<!-- auto-generated by {} -->
{}"""
parser = option.build_parser()
parser.usage = ""
opts = parser.format_help()
opts = opts[8:] # strip 'usage'
opts = re.sub(r"(?m)^(\w+.*)", "## \\1", opts) # group names to headings
opts = opts.replace("\n ", "\n ") # indent by 4
outfile = sys.argv[1] if len(sys.argv) > 1 else util.path("docs", "options.md")
with open(outfile, "w", encoding="utf-8") as fp:
fp.write(TEMPLATE.format(
"/".join(os.path.normpath(__file__).split(os.sep)[-2:]),
opts,
))