Skip to content

Commit f1ef565

Browse files
JohnVillalovosnejch
authored andcommitted
chore(cli): on the CLI help show the API endpoint of resources
This makes it easier for people to map CLI command names to the API. Looks like this: $ gitlab --help <snip> The GitLab resource to manipulate. application API endpoint: /applications application-appearance API endpoint: /application/appearance application-settings API endpoint: /application/settings application-statistics API endpoint: /application/statistics <snip>
1 parent 5a4a940 commit f1ef565

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

gitlab/cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser:
134134
parser = argparse.ArgumentParser(
135135
add_help=add_help,
136136
description="GitLab API Command Line Interface",
137-
formatter_class=VerticalHelpFormatter,
138137
allow_abbrev=False,
139138
)
140139
parser.add_argument("--version", help="Display the version.", action="store_true")

gitlab/v4/cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,12 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
382382

383383
for cls in sorted(classes, key=operator.attrgetter("__name__")):
384384
arg_name = cli.cls_to_gitlab_resource(cls)
385+
mgr_cls_name = f"{cls.__name__}Manager"
386+
mgr_cls = getattr(gitlab.v4.objects, mgr_cls_name)
385387
object_group = subparsers.add_parser(
386-
arg_name, formatter_class=cli.VerticalHelpFormatter
388+
arg_name,
389+
formatter_class=cli.VerticalHelpFormatter,
390+
help=f"API endpoint: {mgr_cls._path}",
387391
)
388392

389393
object_subparsers = object_group.add_subparsers(

tests/functional/cli/test_cli.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ def test_config_error_with_help_prints_help(script_runner):
3434
assert ret.returncode == 0
3535

3636

37-
def test_global_help_prints_resources_vertically(script_runner):
38-
ret = script_runner.run(["gitlab", "--help"])
39-
assert """resource:\n application\n application-appearance\n""" in ret.stdout
40-
assert ret.returncode == 0
41-
42-
4337
def test_resource_help_prints_actions_vertically(script_runner):
4438
ret = script_runner.run(["gitlab", "project", "--help"])
4539
assert """action:\n list\n get""" in ret.stdout

0 commit comments

Comments
 (0)