Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mikf
GitHub Repository: mikf/gallery-dl
Path: blob/master/scripts/options.py
5457 views
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
4
# Copyright 2023 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
parser = option.build_parser()
33
parser.formatter_class = Formatter
34
parser.format_usage = lambda: ""
35
36
opts = parser.format_help()
37
opts = re.sub(r"(?m)^(\w+.*)", "## \\1", opts) # group names to headings
38
opts = opts.replace("\n ", "\n ") # indent by 4
39
40
41
SELF = "/".join(os.path.normpath(__file__).split(os.sep)[-2:])
42
PATH = (sys.argv[1] if len(sys.argv) > 1 else
43
util.path("docs", "options.md"))
44
45
with util.lazy(PATH) as fp:
46
fp.write(f"""# Command-Line Options
47
48
<!-- auto-generated by {SELF} -->
49
{opts[:-1]}""")
50
51