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:
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+ # 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+
109130def _get_base_parser (add_help : bool = True ) -> argparse .ArgumentParser :
110131 parser = argparse .ArgumentParser (
111132 add_help = add_help ,
112133 description = "GitLab API Command Line Interface" ,
113134 allow_abbrev = False ,
135+ formatter_class = VerticalHelpFormatter ,
114136 )
115137 parser .add_argument ("--version" , help = "Display the version." , action = "store_true" )
116138 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:
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" ,
You can’t perform that action at this time.
0 commit comments