File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -106,11 +106,33 @@ def cls_to_gitlab_resource(cls: RESTObject) -> str:
106
106
return dasherized_lowercase .lower ()
107
107
108
108
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
+ # All of our resources are on one line and wrapped inside braces.
115
+ # For example: {application,resource1,resource2}
116
+ # We then put each resource on its own line to make it easier to read.
117
+ if line .strip ().startswith ("{" ):
118
+ leading_whitespace = line .split ("{" )[0 ]
119
+ line = (
120
+ leading_whitespace
121
+ + f",\n { leading_whitespace } " .join (
122
+ line .strip ().strip ("{}" ).split ("," )
123
+ )
124
+ + "\n "
125
+ )
126
+ output += line
127
+ return output
128
+
129
+
109
130
def _get_base_parser (add_help : bool = True ) -> argparse .ArgumentParser :
110
131
parser = argparse .ArgumentParser (
111
132
add_help = add_help ,
112
133
description = "GitLab API Command Line Interface" ,
113
134
allow_abbrev = False ,
135
+ formatter_class = VerticalHelpFormatter ,
114
136
)
115
137
parser .add_argument ("--version" , help = "Display the version." , action = "store_true" )
116
138
parser .add_argument (
Original file line number Diff line number Diff line change @@ -377,7 +377,9 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
377
377
378
378
for cls in sorted (classes , key = operator .attrgetter ("__name__" )):
379
379
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
+ )
381
383
382
384
object_subparsers = object_group .add_subparsers (
383
385
title = "action" ,
You can’t perform that action at this time.
0 commit comments