From 8b425599bcda4f2c1bf893f78e8773653afacff7 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Tue, 12 May 2015 20:33:26 +0200 Subject: improve handling of id attributes in CLI closes #31 --- bin/gitlab | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'bin') diff --git a/bin/gitlab b/bin/gitlab index 3967be0..e9b7eb8 100755 --- a/bin/gitlab +++ b/bin/gitlab @@ -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] @@ -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 @@ -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) -- cgit v1.2.1