Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit65caef4

Browse files
jouvenejch
authored andcommitted
fix(cli): fix action display in --help when there are few actions
fixes#2656
1 parente15349c commit65caef4

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

‎gitlab/cli.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
importos
44
importre
55
importsys
6+
importtextwrap
67
fromtypesimportModuleType
78
fromtypingimport (
89
Any,
@@ -50,11 +51,21 @@ def format_help(self) -> str:
5051
forlineinresult.splitlines(keepends=True):
5152
# All of our resources are on one line and wrapped inside braces.
5253
# For example: {application,resource1,resource2}
54+
# except if there are fewer resources - then the line and help text
55+
# are collapsed on the same line.
56+
# For example: {list} Action to execute on the GitLab resource.
5357
# We then put each resource on its own line to make it easier to read.
5458
ifline.strip().startswith("{"):
55-
choices=line.strip().strip("{}").split(",")
56-
choices_str=f"\n{indent}".join(choices)
57-
line=f"{indent}{choices_str}\n"
59+
choice_string,help_string=line.split("}",1)
60+
choice_list=choice_string.strip(" {").split(",")
61+
help_string=help_string.strip()
62+
63+
ifhelp_string:
64+
help_indent=len(max(choice_list,key=len))*" "
65+
choice_list.append(f"{help_indent}{help_string}")
66+
67+
choices="\n".join(choice_list)
68+
line=f"{textwrap.indent(choices,indent)}\n"
5869
output+=line
5970
returnoutput
6071

‎tests/functional/cli/test_cli.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def test_resource_help_prints_actions_vertically(script_runner):
4646
assertret.returncode==0
4747

4848

49+
deftest_resource_help_prints_actions_vertically_only_one_action(script_runner):
50+
ret=script_runner.run(["gitlab","event","--help"])
51+
assert"""action:\n list\n"""inret.stdout
52+
assertret.returncode==0
53+
54+
4955
@pytest.mark.script_launch_mode("inprocess")
5056
@responses.activate
5157
deftest_defaults_to_gitlab_com(script_runner,resp_get_project,monkeypatch):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp