Skip to content

Commit

Permalink
improve handling of id attributes in CLI
Browse files Browse the repository at this point in the history
closes #31
  • Loading branch information
Gauvain Pocentek committed May 12, 2015
1 parent ede1224 commit 8b42559
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bin/gitlab
Expand Up @@ -87,7 +87,9 @@ def populate_sub_parser_by_class(cls, sub_parser):

elif action_name in [GET, DELETE]:
if cls not in [gitlab.CurrentUser]:
sub_parser_action.add_argument("--id", required=True)
id_attr = cls.idAttr.replace('_', '-')
sub_parser_action.add_argument("--%s" % id_attr,
required=True)
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
required=True)
for x in cls.requiredGetAttrs]
Expand Down Expand Up @@ -126,11 +128,11 @@ def do_auth():
die("Could not connect to GitLab %s (%s)" % (gitlab_url, str(e)))


def get_id():
def get_id(cls):
try:
id = d.pop('id')
id = d.pop(cls.idAttr)
except Exception:
die("Missing --id argument")
die("Missing --%s argument" % cls.idAttr.replace('_', '-'))

return id

Expand Down Expand Up @@ -166,7 +168,7 @@ def do_get(cls, d):

id = None
if cls not in [gitlab.CurrentUser]:
id = get_id()
id = get_id(cls)

try:
o = cls(gl, id, **d)
Expand Down

0 comments on commit 8b42559

Please sign in to comment.