Skip to content

Commit 34e4304

Browse files
author
Gauvain Pocentek
committed
gitlab: warn the user if an action cannot be performed
1 parent 49eab91 commit 34e4304

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

gitlab

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ if gitlab.GitlabObject not in getmro(cls):
8787
die("Unknown object: %s" % what)
8888

8989
if action == "create":
90+
if not cls.canCreate:
91+
die("%s objects can't be created" % what)
92+
9093
try:
9194
o = cls(gl, d)
9295
o.save()
@@ -96,6 +99,9 @@ if action == "create":
9699
sys.exit(0)
97100

98101
elif action == "list":
102+
if not cls.canList:
103+
die("%s objects can't be listed" % what)
104+
99105
try:
100106
l = cls.list(gl, **d)
101107
except Exception as e:
@@ -108,6 +114,9 @@ elif action == "list":
108114
sys.exit(0)
109115

110116
elif action == "get":
117+
if not cls.canGet:
118+
die("%s objects can't be retrieved" % what)
119+
111120
try:
112121
id = d.pop('id')
113122
except:
@@ -123,6 +132,9 @@ elif action == "get":
123132
sys.exit(0)
124133

125134
elif action == "delete":
135+
if not cls.canDelete:
136+
die("%s objects can't be deleted" % what)
137+
126138
try:
127139
id = d.pop('id')
128140
except:
@@ -141,6 +153,9 @@ elif action == "delete":
141153
sys.exit(0)
142154

143155
elif action == "update":
156+
if not cls.canDelete:
157+
die("%s objects can't be updated" % what)
158+
144159
try:
145160
id = d.pop('id')
146161
except:

0 commit comments

Comments
 (0)