Commit 8694bdad authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Separate object/container level args, raise errors

Refs: #4301

-R/--recursive argument will be a container-level only argument,
so all arguments should be separated and raise erros in case of wrong usage
parent 7f85a914
......@@ -38,7 +38,8 @@ from pydoc import pager
from kamaki.cli import command
from kamaki.cli.command_tree import CommandTree
from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError
from kamaki.cli.errors import (
raiseCLIError, CLISyntaxError, CLIBaseUrlError, CLIInvalidArgument)
from kamaki.cli.utils import (
format_size, to_bytes, bold, get_path_size, guess_mime_type)
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument
......@@ -338,7 +339,10 @@ class file_list(_file_container_command, _optional_json, _name_filter):
'Show only objects that match exactly with path',
enum=FlagArgument('Enumerate results', '--enumerate')
enum=FlagArgument('Enumerate results', '--enumerate'),
'Recursively list containers and their contents',
('-R', '--recursive'))
def print_objects(self, object_list):
......@@ -392,13 +396,37 @@ class file_list(_file_container_command, _optional_json, _name_filter):
def _argument_context_check(self):
container_level_only = ('recursive', )
object_level_only = ('delimiter', 'path', 'exact_match')
details, mistake = [], ''
if self.container:
for term in container_level_only:
if self[term]:
details = [
'This is a container-level argument',
'Use it without a <container> parameter']
mistake = self.arguments[term]
for term in object_level_only:
if self[term]:
details = [
'This is an opbject-level argument',
'Use it with a <container> parameter']
mistake = self.arguments[term]
if mistake and details:
raise CLIInvalidArgument(
'Invalid use of %s argument' % '/'.join(mistake.parsed_name),
details=details + ['Try --help for more details'])
def _run(self):
files, prnt = None, None
if self.container is None:
if not self.container:
r = self.client.account_get(
limit=False if self['more'] else self['limit'],
......@@ -97,6 +97,11 @@ class CLISyntaxError(CLIError):
super(CLISyntaxError, self).__init__(message, details, importance)
class CLIInvalidArgument(CLISyntaxError):
def __init__(self, message='Invalid Argument', details=[], importance=1):
super(CLIInvalidArgument, self).__init__(message, details, importance)
class CLIUnknownCommand(CLIError):
def __init__(self, message='Unknown Command', details=[], importance=1):
super(CLIUnknownCommand, self).__init__(message, details, importance)
......@@ -391,6 +391,16 @@ class CLISyntaxError(TestCase):
self.assertEqual(clise.importance, 1)
class CLIInvalidArgument(TestCase):
def test___init__(self):
from kamaki.cli.errors import CLIInvalidArgument
cliia = CLIInvalidArgument()
self.assertEqual('%s' % cliia, 'Invalid Argument\n')
self.assertEqual(cliia.details, [])
self.assertEqual(cliia.importance, 1)
class CLIUnknownCommand(TestCase):
def test___init__(self):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment