Revision 8694bdad

b/kamaki/cli/commands/pithos.py
38 38

  
39 39
from kamaki.cli import command
40 40
from kamaki.cli.command_tree import CommandTree
41
from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError
41
from kamaki.cli.errors import (
42
    raiseCLIError, CLISyntaxError, CLIBaseUrlError, CLIInvalidArgument)
42 43
from kamaki.cli.utils import (
43 44
    format_size, to_bytes, bold, get_path_size, guess_mime_type)
44 45
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument
......
338 339
        exact_match=FlagArgument(
339 340
            'Show only objects that match exactly with path',
340 341
            '--exact-match'),
341
        enum=FlagArgument('Enumerate results', '--enumerate')
342
        enum=FlagArgument('Enumerate results', '--enumerate'),
343
        recursive=FlagArgument(
344
            'Recursively list containers and their contents',
345
            ('-R', '--recursive'))
342 346
    )
343 347

  
344 348
    def print_objects(self, object_list):
......
392 396
                else:
393 397
                    self.writeln(cname)
394 398

  
399
    def _argument_context_check(self):
400
        container_level_only = ('recursive', )
401
        object_level_only = ('delimiter', 'path', 'exact_match')
402
        details, mistake = [], ''
403
        if self.container:
404
            for term in container_level_only:
405
                if self[term]:
406
                    details = [
407
                        'This is a container-level argument',
408
                        'Use it without a <container> parameter']
409
                    mistake = self.arguments[term]
410
        else:
411
            for term in object_level_only:
412
                if self[term]:
413
                    details = [
414
                        'This is an opbject-level argument',
415
                        'Use it with a <container> parameter']
416
                    mistake = self.arguments[term]
417
        if mistake and details:
418
            raise CLIInvalidArgument(
419
                'Invalid use of %s argument' % '/'.join(mistake.parsed_name),
420
                details=details + ['Try --help for more details'])
421

  
395 422
    @errors.generic.all
396 423
    @errors.pithos.connection
397 424
    @errors.pithos.object_path
398 425
    @errors.pithos.container
399 426
    def _run(self):
400 427
        files, prnt = None, None
401
        if self.container is None:
428
        self._argument_context_check()
429
        if not self.container:
402 430
            r = self.client.account_get(
403 431
                limit=False if self['more'] else self['limit'],
404 432
                marker=self['marker'],
b/kamaki/cli/errors.py
97 97
        super(CLISyntaxError, self).__init__(message, details, importance)
98 98

  
99 99

  
100
class CLIInvalidArgument(CLISyntaxError):
101
    def __init__(self, message='Invalid Argument', details=[], importance=1):
102
        super(CLIInvalidArgument, self).__init__(message, details, importance)
103

  
104

  
100 105
class CLIUnknownCommand(CLIError):
101 106
    def __init__(self, message='Unknown Command', details=[], importance=1):
102 107
        super(CLIUnknownCommand, self).__init__(message, details, importance)
b/kamaki/cli/test.py
391 391
        self.assertEqual(clise.importance, 1)
392 392

  
393 393

  
394
class CLIInvalidArgument(TestCase):
395

  
396
    def test___init__(self):
397
        from kamaki.cli.errors import CLIInvalidArgument
398
        cliia = CLIInvalidArgument()
399
        self.assertEqual('%s' % cliia, 'Invalid Argument\n')
400
        self.assertEqual(cliia.details, [])
401
        self.assertEqual(cliia.importance, 1)
402

  
403

  
394 404
class CLIUnknownCommand(TestCase):
395 405

  
396 406
    def test___init__(self):

Also available in: Unified diff