From 4c998eaa2a58efa25ae08bfe084c3ef76df98644 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Sat, 22 Jun 2013 10:39:37 +0200 Subject: [PATCH] gitlab: make the current-user option work --- gitlab | 21 ++++++++++++--------- gitlab.py | 6 ++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/gitlab b/gitlab index c5b8f63ef..3e9866696 100755 --- a/gitlab +++ b/gitlab @@ -59,8 +59,9 @@ def actionHelpList(cls): detail += " " detail += "--page=ARG --per-page=ARG" elif action in ['get', 'delete']: - detail = "--id=ARG " - detail += " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredGetAttrs]) + if cls not in [gitlab.CurrentUser]: + detail = "--id=ARG " + detail += " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredGetAttrs]) elif action == 'create': detail = " ".join(["--%s=ARG" % x.replace('_', '-') for x in cls.requiredCreateAttrs]) if detail: @@ -113,7 +114,7 @@ args = [] d = {} for arg in sys.argv[1:]: if arg.startswith('--'): - arg = arg[2:].replace('-', '_') + arg = arg[2:] if arg == 'help': usage() @@ -122,8 +123,8 @@ for arg in sys.argv[1:]: verbose = True continue - k, v = arg.split('=', 2) - k = k.strip() + k, v = arg.split('=', 1) + k = k.strip().replace('_', '-') v = v.strip() if k == 'gitlab': @@ -219,10 +220,12 @@ elif action == "get": if not cls.canGet: die("%s objects can't be retrieved" % what) - try: - id = d.pop('id') - except: - die("Missing --id argument") + id = None + if cls not in [gitlab.CurrentUser]: + try: + id = d.pop('id') + except: + die("Missing --id argument") try: o = cls(gl, id, **d) diff --git a/gitlab.py b/gitlab.py index 515eb60c6..38889357d 100644 --- a/gitlab.py +++ b/gitlab.py @@ -278,6 +278,9 @@ def create(self, obj): url = obj._url % obj.__dict__ url = '%s%s?private_token=%s' % (self._url, url, self.private_token) + print url + print obj.__dict__ + try: # TODO: avoid too much work on the server side by filtering the # __dict__ keys @@ -529,6 +532,8 @@ class User(GitlabObject): class CurrentUserKey(GitlabObject): _url = '/user/keys' canUpdate = False + shortPrintAttr = 'title' + requiredCreateAttrs = ['title', 'key'] class CurrentUser(GitlabObject): @@ -537,6 +542,7 @@ class CurrentUser(GitlabObject): canCreate = False canUpdate = False canDelete = False + shortPrintAttr = 'username' def Key(self, id=None, **kwargs): if id is None: