summaryrefslogtreecommitdiff
path: root/gitlab
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2023-04-07 20:01:09 +0200
committerNejc Habjan <hab.nejc@gmail.com>2023-04-11 13:53:12 +0200
commit8bf53c8b31704bdb31ffc5cf107cc5fba5dad457 (patch)
treedb987cb340e0544d655a5701822dae6442b22ca3 /gitlab
parentce84f2e64a640e0d025a7ba3a436f347ad25e88e (diff)
downloadgitlab-8bf53c8b31704bdb31ffc5cf107cc5fba5dad457.tar.gz
fix(cli): warn user when no fields are displayed
Diffstat (limited to 'gitlab')
-rw-r--r--gitlab/v4/cli.py44
1 files changed, 28 insertions, 16 deletions
diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py
index 0c3a655..dbf0eb0 100644
--- a/gitlab/v4/cli.py
+++ b/gitlab/v4/cli.py
@@ -482,23 +482,35 @@ class LegacyPrinter:
if obj._id_attr:
attrs.pop(obj._id_attr)
display_dict(attrs, padding)
+ return
- else:
- if TYPE_CHECKING:
- assert isinstance(obj, gitlab.base.RESTObject)
- if obj._id_attr:
- id = getattr(obj, obj._id_attr)
- print(f"{obj._id_attr.replace('_', '-')}: {id}")
- if obj._repr_attr:
- value = getattr(obj, obj._repr_attr, "None") or "None"
- value = value.replace("\r", "").replace("\n", " ")
- # If the attribute is a note (ProjectCommitComment) then we do
- # some modifications to fit everything on one line
- line = f"{obj._repr_attr}: {value}"
- # ellipsize long lines (comments)
- if len(line) > 79:
- line = f"{line[:76]}..."
- print(line)
+ lines = []
+
+ if TYPE_CHECKING:
+ assert isinstance(obj, gitlab.base.RESTObject)
+
+ if obj._id_attr:
+ id = getattr(obj, obj._id_attr)
+ lines.append(f"{obj._id_attr.replace('_', '-')}: {id}")
+ if obj._repr_attr:
+ value = getattr(obj, obj._repr_attr, "None") or "None"
+ value = value.replace("\r", "").replace("\n", " ")
+ # If the attribute is a note (ProjectCommitComment) then we do
+ # some modifications to fit everything on one line
+ line = f"{obj._repr_attr}: {value}"
+ # ellipsize long lines (comments)
+ if len(line) > 79:
+ line = f"{line[:76]}..."
+ lines.append(line)
+
+ if lines:
+ print("\n".join(lines))
+ return
+
+ print(
+ f"No default fields to show for {obj!r}. "
+ f"Please use '--verbose' or the JSON/YAML formatters."
+ )
def display_list(
self,