diff --git a/gitlab/cli.py b/gitlab/cli.py index 979396407..4a359c0fd 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -106,11 +106,33 @@ def cls_to_gitlab_resource(cls: RESTObject) -> str: return dasherized_lowercase.lower() +class VerticalHelpFormatter(argparse.HelpFormatter): + def format_help(self) -> str: + result = super().format_help() + output = "" + for line in result.splitlines(keepends=True): + # All of our resources are on one line and wrapped inside braces. + # For example: {application,resource1,resource2} + # We then put each resource on its own line to make it easier to read. + if line.strip().startswith("{"): + leading_whitespace = line.split("{")[0] + line = ( + leading_whitespace + + f",\n{leading_whitespace}".join( + line.strip().strip("{}").split(",") + ) + + "\n" + ) + output += line + return output + + def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser: parser = argparse.ArgumentParser( add_help=add_help, description="GitLab API Command Line Interface", allow_abbrev=False, + formatter_class=VerticalHelpFormatter, ) parser.add_argument("--version", help="Display the version.", action="store_true") parser.add_argument( diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index 90b6ba6c0..48369f657 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -377,7 +377,9 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser: for cls in sorted(classes, key=operator.attrgetter("__name__")): arg_name = cli.cls_to_gitlab_resource(cls) - object_group = subparsers.add_parser(arg_name) + object_group = subparsers.add_parser( + arg_name, formatter_class=cli.VerticalHelpFormatter + ) object_subparsers = object_group.add_subparsers( title="action",