diff --git a/gitlab/cli.py b/gitlab/cli.py index 17917f564..732b65411 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -165,13 +165,13 @@ def main(): if args.fields: fields = [x.strip() for x in args.fields.split(',')] debug = args.debug - action = args.action + action = args.whaction what = args.what args = args.__dict__ # Remove CLI behavior-related args - for item in ('gitlab', 'config_file', 'verbose', 'debug', 'what', 'action', - 'version', 'output'): + for item in ('gitlab', 'config_file', 'verbose', 'debug', 'what', + 'whaction', 'version', 'output'): args.pop(item) args = {k: _parse_value(v) for k, v in args.items() if v is not None} diff --git a/gitlab/tests/test_cli.py b/gitlab/tests/test_cli.py index 3fe4a4e17..dbc6d6f3b 100644 --- a/gitlab/tests/test_cli.py +++ b/gitlab/tests/test_cli.py @@ -111,7 +111,7 @@ def test_parse_args(self): parser = cli._get_parser(gitlab.v4.cli) args = parser.parse_args(['project', 'list']) self.assertEqual(args.what, 'project') - self.assertEqual(args.action, 'list') + self.assertEqual(args.whaction, 'list') def test_parser(self): parser = cli._get_parser(gitlab.v4.cli) diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index 242874d1a..4c4318f1e 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -230,7 +230,10 @@ def _populate_sub_parser_by_class(cls, sub_parser): for x in required if x != cls._id_attr] [sub_parser_action.add_argument("--%s" % x.replace('_', '-'), required=False) - for x in optional if x != cls._id_attr] + for x in optional if x != cls._id_attr and x not in ['recursive']] + [sub_parser_action.add_argument("--%s" % x, action='store_true', + required=False) + for x in optional if x in ['recursive']] if mgr_cls.__name__ in cli.custom_actions: name = mgr_cls.__name__ @@ -273,7 +276,7 @@ def extend_parser(parser): object_subparsers = object_group.add_subparsers( title='action', - dest='action', help="Action to execute.") + dest='whaction', help="Action to execute.") _populate_sub_parser_by_class(cls, object_subparsers) object_subparsers.required = True @@ -357,7 +360,7 @@ def display_dict(d, padding): id = getattr(obj, obj._id_attr) print('%s: %s' % (obj._id_attr.replace('_', '-'), id)) if hasattr(obj, '_short_print_attr'): - value = getattr(obj, obj._short_print_attr) + value = getattr(obj, obj._short_print_attr) or 'None' value = value.replace('\r', '').replace('\n', ' ') # If the attribute is a note (ProjectCommitComment) then we do # some modifications to fit everything on one line diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index c3f8a8154..2d7daa293 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -909,7 +909,7 @@ def transfer_project(self, to_project_id, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabTransferProjectError: If the project could not be transfered """ - path = '/groups/%d/projects/%d' % (self.id, to_project_id) + path = '/groups/%s/projects/%s' % (self.id, to_project_id) self.manager.gitlab.http_post(path, **kwargs) @cli.register_custom_action('Group', ('scope', 'search')) @@ -930,7 +930,7 @@ def search(self, scope, search, **kwargs): GitlabList: A list of dicts describing the resources found. """ data = {'scope': scope, 'search': search} - path = '/groups/%d/search' % self.get_id() + path = '/groups/%s/search' % self.get_id() return self.manager.gitlab.http_list(path, query_data=data, **kwargs) @cli.register_custom_action('Group', ('cn', 'group_access', 'provider')) @@ -949,7 +949,7 @@ def add_ldap_group_link(self, cn, group_access, provider, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request """ - path = '/groups/%d/ldap_group_links' % self.get_id() + path = '/groups/%s/ldap_group_links' % self.get_id() data = {'cn': cn, 'group_access': group_access, 'provider': provider} self.manager.gitlab.http_post(path, post_data=data, **kwargs) @@ -967,7 +967,7 @@ def delete_ldap_group_link(self, cn, provider=None, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server cannot perform the request """ - path = '/groups/%d/ldap_group_links' % self.get_id() + path = '/groups/%s/ldap_group_links' % self.get_id() if provider is not None: path += '/%s' % provider path += '/%s' % cn @@ -985,7 +985,7 @@ def ldap_sync(self, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request """ - path = '/groups/%d/ldap_sync' % self.get_id() + path = '/groups/%s/ldap_sync' % self.get_id() self.manager.gitlab.http_post(path, **kwargs) @@ -3216,7 +3216,7 @@ def download(self, streamed=False, action=None, chunk_size=1024, **kwargs): Returns: str: The blob content if streamed is False, None otherwise """ - path = '/projects/%d/export/download' % self.project_id + path = '/projects/%s/export/download' % self.project_id result = self.manager.gitlab.http_get(path, streamed=streamed, raw=True, **kwargs) return utils.response_content(result, streamed, action, chunk_size) @@ -3282,7 +3282,8 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): ('wikis', 'ProjectWikiManager'), ) - @cli.register_custom_action('Project', tuple(), ('path', 'ref')) + @cli.register_custom_action('Project', tuple(), + ('path', 'ref', 'recursive')) @exc.on_http_error(exc.GitlabGetError) def repository_tree(self, path='', ref='', recursive=False, **kwargs): """Return a list of files in the repository. @@ -3717,7 +3718,7 @@ def snapshot(self, wiki=False, streamed=False, action=None, Returns: str: The uncompressed tar archive of the repository """ - path = '/projects/%d/snapshot' % self.get_id() + path = '/projects/%s/snapshot' % self.get_id() result = self.manager.gitlab.http_get(path, streamed=streamed, raw=True, **kwargs) return utils.response_content(result, streamed, action, chunk_size) @@ -3740,7 +3741,7 @@ def search(self, scope, search, **kwargs): GitlabList: A list of dicts describing the resources found. """ data = {'scope': scope, 'search': search} - path = '/projects/%d/search' % self.get_id() + path = '/projects/%s/search' % self.get_id() return self.manager.gitlab.http_list(path, query_data=data, **kwargs) @cli.register_custom_action('Project') @@ -3755,7 +3756,7 @@ def mirror_pull(self, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request """ - path = '/projects/%d/mirror/pull' % self.get_id() + path = '/projects/%s/mirror/pull' % self.get_id() self.manager.gitlab.http_post(path, **kwargs) @cli.register_custom_action('Project', ('to_namespace', )) @@ -3772,7 +3773,7 @@ def transfer_project(self, to_namespace, **kwargs): GitlabAuthenticationError: If authentication is not correct GitlabTransferProjectError: If the project could not be transfered """ - path = '/projects/%d/transfer' % (self.id,) + path = '/projects/%s/transfer' % (self.id,) self.manager.gitlab.http_put(path, post_data={"namespace": to_namespace}, **kwargs)