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

Commit8bf53c8

Browse files
committed
fix(cli): warn user when no fields are displayed
1 parentce84f2e commit8bf53c8

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

‎gitlab/v4/cli.py‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -482,23 +482,35 @@ def display_dict(d: Dict[str, Any], padding: int) -> None:
482482
ifobj._id_attr:
483483
attrs.pop(obj._id_attr)
484484
display_dict(attrs,padding)
485+
return
485486

486-
else:
487-
ifTYPE_CHECKING:
488-
assertisinstance(obj,gitlab.base.RESTObject)
489-
ifobj._id_attr:
490-
id=getattr(obj,obj._id_attr)
491-
print(f"{obj._id_attr.replace('_','-')}:{id}")
492-
ifobj._repr_attr:
493-
value=getattr(obj,obj._repr_attr,"None")or"None"
494-
value=value.replace("\r","").replace("\n"," ")
495-
# If the attribute is a note (ProjectCommitComment) then we do
496-
# some modifications to fit everything on one line
497-
line=f"{obj._repr_attr}:{value}"
498-
# ellipsize long lines (comments)
499-
iflen(line)>79:
500-
line=f"{line[:76]}..."
501-
print(line)
487+
lines= []
488+
489+
ifTYPE_CHECKING:
490+
assertisinstance(obj,gitlab.base.RESTObject)
491+
492+
ifobj._id_attr:
493+
id=getattr(obj,obj._id_attr)
494+
lines.append(f"{obj._id_attr.replace('_','-')}:{id}")
495+
ifobj._repr_attr:
496+
value=getattr(obj,obj._repr_attr,"None")or"None"
497+
value=value.replace("\r","").replace("\n"," ")
498+
# If the attribute is a note (ProjectCommitComment) then we do
499+
# some modifications to fit everything on one line
500+
line=f"{obj._repr_attr}:{value}"
501+
# ellipsize long lines (comments)
502+
iflen(line)>79:
503+
line=f"{line[:76]}..."
504+
lines.append(line)
505+
506+
iflines:
507+
print("\n".join(lines))
508+
return
509+
510+
print(
511+
f"No default fields to show for{obj!r}. "
512+
f"Please use '--verbose' or the JSON/YAML formatters."
513+
)
502514

503515
defdisplay_list(
504516
self,

‎tests/functional/cli/test_cli.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,13 @@ def test_cli_fields_in_list(gitlab_cli, project_file, format, loader):
182182

183183
content=loader(ret.stdout.strip())
184184
assert ["default_branch"initemforitemincontent]
185+
186+
187+
deftest_cli_display_without_fields_warns(gitlab_cli,project):
188+
cmd= ["project-ci-lint","get","--project-id",project.id]
189+
190+
ret=gitlab_cli(cmd)
191+
assertret.success
192+
193+
assert"No default fields to show"inret.stdout
194+
assert"merged_yaml"notinret.stdout

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp