Skip to content

Commit 72bf9c9

Browse files
feat: john's ugly vertical help formatter :)
1 parent 510ec30 commit 72bf9c9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

gitlab/cli.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,30 @@ def cls_to_gitlab_resource(cls: RESTObject) -> str:
106106
return dasherized_lowercase.lower()
107107

108108

109+
class VerticalHelpFormatter(argparse.HelpFormatter):
110+
def format_help(self) -> str:
111+
result = super().format_help()
112+
output = ""
113+
for line in result.splitlines(keepends=True):
114+
if line.strip().startswith("{"):
115+
leading_whitespace = line.split("{")[0]
116+
line = (
117+
leading_whitespace
118+
+ f",\n{leading_whitespace}".join(
119+
line.strip().strip("{}").split(",")
120+
)
121+
+ "\n"
122+
)
123+
output += line
124+
return output
125+
126+
109127
def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser:
110128
parser = argparse.ArgumentParser(
111129
add_help=add_help,
112130
description="GitLab API Command Line Interface",
113131
allow_abbrev=False,
132+
formatter_class=VerticalHelpFormatter,
114133
)
115134
parser.add_argument("--version", help="Display the version.", action="store_true")
116135
parser.add_argument(

gitlab/v4/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
377377

378378
for cls in sorted(classes, key=operator.attrgetter("__name__")):
379379
arg_name = cli.cls_to_gitlab_resource(cls)
380-
object_group = subparsers.add_parser(arg_name)
380+
object_group = subparsers.add_parser(
381+
arg_name, formatter_class=cli.VerticalHelpFormatter
382+
)
381383

382384
object_subparsers = object_group.add_subparsers(
383385
title="action",

0 commit comments

Comments
 (0)