Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mikf
GitHub Repository: mikf/gallery-dl
Path: blob/master/scripts/options.py
8747 views
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
4
# Copyright 2023-2026 Mike Fährmann
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License version 2 as
8
# published by the Free Software Foundation.
9
10
"""Generate a document listing gallery-dl's command-line arguments"""
11
12
import os
13
import re
14
import sys
15
16
import util
17
18
import gallery_dl.util
19
gallery_dl.util.EXECUTABLE = True
20
from gallery_dl import option # noqa E402
21
22
23
class Formatter(option.Formatter):
24
def __init__(self, prog):
25
option.argparse.HelpFormatter.__init__(
26
self, prog, max_help_position=30, width=77)
27
28
def add_usage(self, usage, actions, groups):
29
pass
30
31
32
def repl(match):
33
cat = match[1].rstrip(":")
34
toc.append(f"* [{cat}](#{cat.lower().replace(' ', '-')})")
35
return f"## {cat}:"
36
37
38
parser = option.build_parser()
39
parser.formatter_class = Formatter
40
parser.format_usage = lambda: ""
41
42
toc = []
43
opts = parser.format_help()
44
opts = re.sub(r"(?m)^(\w+.*)", repl, opts) # group names to headings
45
opts = opts.replace("\n ", "\n ") # indent by 4
46
toc = "\n".join(toc)
47
48
SELF = "/".join(os.path.normpath(__file__).split(os.sep)[-2:])
49
PATH = (sys.argv[1] if len(sys.argv) > 1 else
50
util.path("docs", "options.md"))
51
52
with util.lazy(PATH) as fp:
53
fp.write(f"""\
54
# Command-Line Options
55
56
<!-- auto-generated by {SELF} -->
57
58
59
## Table of Contents
60
61
{toc}
62
63
{opts}\
64
""")
65
66