From 1f429da6501983722cac9931ea189ee390c80ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 17 Jun 2025 18:51:48 +0200 Subject: [PATCH] [scripts/options] make output width independent of terminal size --- scripts/options.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/scripts/options.py b/scripts/options.py index f9f0ace1..c71a53ea 100755 --- a/scripts/options.py +++ b/scripts/options.py @@ -20,26 +20,32 @@ gallery_dl.util.EXECUTABLE = True from gallery_dl import option # noqa E402 -TEMPLATE = """# Command-Line Options +class Formatter(option.Formatter): + def __init__(self, prog): + option.argparse.HelpFormatter.__init__( + self, prog, max_help_position=30, width=77) - - -{}""" + def add_usage(self, usage, actions, groups): + pass parser = option.build_parser() -parser.usage = "" +parser.formatter_class = Formatter +parser.format_usage = lambda: "" 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 +SELF = "/".join(os.path.normpath(__file__).split(os.sep)[-2:]) PATH = (sys.argv[1] if len(sys.argv) > 1 else util.path("docs", "options.md")) + with util.lazy(PATH) as fp: - fp.write(TEMPLATE.format( - "/".join(os.path.normpath(__file__).split(os.sep)[-2:]), - opts, - )) + fp.write(f"""# Command-Line Options + + + + +{opts}""")