~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Martin Pool
  • Date: 2006-06-15 05:36:34 UTC
  • mto: This revision was merged to the branch mainline in revision 1797.
  • Revision ID: mbp@sourcefrog.net-20060615053634-4fd52ba691855659
Clean up many exception classes.

Errors indicating a user error are now shown with is_user_error on the
exception; use this rather than hardcoding a list of exceptions that should be
handled this way.

Exceptions now inherit from BzrNewException where possible to use consistent
formatting method.

Remove rather obsolete docstring test on Branch.missing_revisions.

Remove dead code from find_merge_base.


Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
import errno
35
35
 
36
36
import bzrlib
 
37
import bzrlib.errors as errors
37
38
from bzrlib.errors import (BzrError,
 
39
                           BzrCommandError,
38
40
                           BzrCheckError,
39
 
                           BzrCommandError,
40
 
                           BzrOptionError,
41
41
                           NotBranchError)
42
42
from bzrlib.option import Option
43
43
from bzrlib.revisionspec import RevisionSpec
145
145
    if cmd_obj:
146
146
        return cmd_obj
147
147
 
148
 
    raise BzrCommandError("unknown command %r" % cmd_name)
 
148
    raise BzrCommandError('unknown command "%s"' % cmd_name)
149
149
 
150
150
 
151
151
class Command(object):
233
233
        for oname in opts:
234
234
            if oname not in allowed_names:
235
235
                raise BzrCommandError("option '--%s' is not allowed for"
236
 
                                      " command %r" % (oname, self.name()))
 
236
                                " command %r" % (oname, self.name()))
237
237
        # mix arguments and options into one dictionary
238
238
        cmdargs = _match_argform(self.name(), self.takes_args, args)
239
239
        cmdopts = {}
337
337
                    else:
338
338
                        optname = a[2:]
339
339
                    if optname not in cmd_options:
340
 
                        raise BzrOptionError('unknown long option %r for'
341
 
                                             ' command %s' % 
342
 
                                             (a, command.name()))
 
340
                        raise BzrCommandError('unknown option "%s"' % a)
343
341
                else:
344
342
                    shortopt = a[1:]
345
343
                    if shortopt in Option.SHORT_OPTIONS:
354
352
                        if shortopt not in Option.SHORT_OPTIONS:
355
353
                            # We didn't find the multi-character name, and we
356
354
                            # didn't find the single char name
357
 
                            raise BzrError('unknown short option %r' % a)
 
355
                            raise BzrCommandError('unknown option "%s"' % a)
358
356
                        optname = Option.SHORT_OPTIONS[shortopt].name
359
357
 
360
358
                        if a[2:]:
371
369
                                # This option takes an argument, so pack it
372
370
                                # into the array
373
371
                                optarg = a[2:]
374
 
                
375
372
                    if optname not in cmd_options:
376
 
                        raise BzrOptionError('unknown short option %r for'
377
 
                                             ' command %s' % 
378
 
                                             (shortopt, command.name()))
 
373
                        raise BzrCommandError('unknown option "%s"' % shortopt)
379
374
                if optname in opts:
380
375
                    # XXX: Do we ever want to support this, e.g. for -r?
381
376
                    if proc_aliasarg:
382
 
                        raise BzrError('repeated option %r' % a)
 
377
                        raise BzrCommandError('repeated option %r' % a)
383
378
                    elif optname in alias_opts:
384
379
                        # Replace what's in the alias with what's in the real
385
380
                        # argument
388
383
                        proc_argv.insert(0, a)
389
384
                        continue
390
385
                    else:
391
 
                        raise BzrError('repeated option %r' % a)
 
386
                        raise BzrCommandError('repeated option %r' % a)
392
387
                    
393
388
                option_obj = cmd_options[optname]
394
389
                optargfn = option_obj.type
395
390
                if optargfn:
396
391
                    if optarg == None:
397
392
                        if not proc_argv:
398
 
                            raise BzrError('option %r needs an argument' % a)
 
393
                            raise BzrCommandError('option %r needs an argument' % a)
399
394
                        else:
400
395
                            optarg = proc_argv.pop(0)
401
396
                    opts[optname] = optargfn(optarg)
403
398
                        alias_opts[optname] = optargfn(optarg)
404
399
                else:
405
400
                    if optarg != None:
406
 
                        raise BzrError('option %r takes no argument' % optname)
 
401
                        raise BzrCommandError('option %r takes no argument' % optname)
407
402
                    opts[optname] = True
408
403
                    if proc_aliasarg:
409
404
                        alias_opts[optname] = True
440
435
                raise BzrCommandError("command %r needs one or more %s"
441
436
                        % (cmd, argname.upper()))
442
437
            argdict[argname + '_list'] = args[:-1]
443
 
            args[:-1] = []                
 
438
            args[:-1] = []
444
439
        else:
445
440
            # just a plain arg
446
441
            argname = ap