Skip to content

Commit 8b42559

Browse files
author
Gauvain Pocentek
committed
improve handling of id attributes in CLI
closes #31
1 parent ede1224 commit 8b42559

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

bin/gitlab

+7-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ def populate_sub_parser_by_class(cls, sub_parser):
8787

8888
elif action_name in [GET, DELETE]:
8989
if cls not in [gitlab.CurrentUser]:
90-
sub_parser_action.add_argument("--id", required=True)
90+
id_attr = cls.idAttr.replace('_', '-')
91+
sub_parser_action.add_argument("--%s" % id_attr,
92+
required=True)
9193
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
9294
required=True)
9395
for x in cls.requiredGetAttrs]
@@ -126,11 +128,11 @@ def do_auth():
126128
die("Could not connect to GitLab %s (%s)" % (gitlab_url, str(e)))
127129

128130

129-
def get_id():
131+
def get_id(cls):
130132
try:
131-
id = d.pop('id')
133+
id = d.pop(cls.idAttr)
132134
except Exception:
133-
die("Missing --id argument")
135+
die("Missing --%s argument" % cls.idAttr.replace('_', '-'))
134136

135137
return id
136138

@@ -166,7 +168,7 @@ def do_get(cls, d):
166168

167169
id = None
168170
if cls not in [gitlab.CurrentUser]:
169-
id = get_id()
171+
id = get_id(cls)
170172

171173
try:
172174
o = cls(gl, id, **d)

0 commit comments

Comments
 (0)