211
@deprecated_method(zero_eight)
212
211
def run_argv(self, argv):
213
"""Parse command line and run.
215
See run_argv_aliases for the 0.8 and beyond api.
217
return self.run_argv_aliases(argv)
219
def run_argv_aliases(self, argv, alias_argv=None):
220
"""Parse the command line and run with extra aliases in alias_argv."""
221
args, opts = parse_args(self, argv, alias_argv)
212
"""Parse command line and run."""
213
args, opts = parse_args(self, argv)
222
214
if 'help' in opts: # e.g. bzr add --help
223
215
from bzrlib.help import help_on_command
224
216
help_on_command(self.name())
305
297
# TODO: chop up this beast; make it a method of the Command
310
301
cmd_options = command.options()
312
proc_aliasarg = True # Are we processing alias_argv now?
313
for proc_argv in alias_argv, argv:
320
# We've received a standalone -- No more flags
324
# option names must not be unicode
328
mutter(" got option %r", a)
330
optname, optarg = a[2:].split('=', 1)
333
if optname not in cmd_options:
334
raise BzrOptionError('unknown long option %r for'
339
if shortopt in Option.SHORT_OPTIONS:
340
# Multi-character options must have a space to delimit
342
# ^^^ what does this mean? mbp 20051014
343
optname = Option.SHORT_OPTIONS[shortopt].name
345
# Single character short options, can be chained,
346
# and have their value appended to their name
348
if shortopt not in Option.SHORT_OPTIONS:
349
# We didn't find the multi-character name, and we
350
# didn't find the single char name
351
raise BzrError('unknown short option %r' % a)
352
optname = Option.SHORT_OPTIONS[shortopt].name
309
# We've received a standalone -- No more flags
313
# option names must not be unicode
317
mutter(" got option %r", a)
319
optname, optarg = a[2:].split('=', 1)
322
if optname not in cmd_options:
323
raise BzrOptionError('unknown long option %r for command %s'
324
% (a, command.name()))
327
if shortopt in Option.SHORT_OPTIONS:
328
# Multi-character options must have a space to delimit
330
# ^^^ what does this mean? mbp 20051014
331
optname = Option.SHORT_OPTIONS[shortopt].name
333
# Single character short options, can be chained,
334
# and have their value appended to their name
336
if shortopt not in Option.SHORT_OPTIONS:
337
# We didn't find the multi-character name, and we
338
# didn't find the single char name
339
raise BzrError('unknown short option %r' % a)
340
optname = Option.SHORT_OPTIONS[shortopt].name
355
# There are extra things on this option
356
# see if it is the value, or if it is another
358
optargfn = Option.OPTIONS[optname].type
360
# This option does not take an argument, so the
361
# next entry is another short option, pack it
363
proc_argv.insert(0, '-' + a[2:])
365
# This option takes an argument, so pack it
343
# There are extra things on this option
344
# see if it is the value, or if it is another
346
optargfn = Option.OPTIONS[optname].type
348
# This option does not take an argument, so the
349
# next entry is another short option, pack it back
351
argv.insert(0, '-' + a[2:])
353
# This option takes an argument, so pack it
357
if optname not in cmd_options:
358
raise BzrOptionError('unknown short option %r for command'
359
' %s' % (shortopt, command.name()))
361
# XXX: Do we ever want to support this, e.g. for -r?
362
raise BzrError('repeated option %r' % a)
369
if optname not in cmd_options:
370
raise BzrOptionError('unknown short option %r for'
372
(shortopt, command.name()))
374
# XXX: Do we ever want to support this, e.g. for -r?
376
raise BzrError('repeated option %r' % a)
377
elif optname in alias_opts:
378
# Replace what's in the alias with what's in the real
380
del alias_opts[optname]
382
proc_argv.insert(0, a)
364
option_obj = cmd_options[optname]
365
optargfn = option_obj.type
369
raise BzrError('option %r needs an argument' % a)
385
raise BzrError('repeated option %r' % a)
387
option_obj = cmd_options[optname]
388
optargfn = option_obj.type
392
raise BzrError('option %r needs an argument' % a)
394
optarg = proc_argv.pop(0)
395
opts[optname] = optargfn(optarg)
397
alias_opts[optname] = optargfn(optarg)
400
raise BzrError('option %r takes no argument' % optname)
403
alias_opts[optname] = True
372
opts[optname] = optargfn(optarg)
406
proc_aliasarg = False # Done with alias argv
375
raise BzrError('option %r takes no argument' % optname)
407
379
return args, opts
475
447
os.remove(pfname)
478
def apply_lsprofiled(filename, the_callable, *args, **kwargs):
450
def apply_lsprofiled(the_callable, *args, **kwargs):
479
451
from bzrlib.lsprof import profile
481
ret, stats = profile(the_callable, *args, **kwargs)
452
ret,stats = profile(the_callable,*args,**kwargs)
487
cPickle.dump(stats, open(filename, 'w'), 2)
488
print 'Profile data written to %r.' % filename
493
"""Return an expanded alias, or None if no alias exists"""
495
alias = bzrlib.config.GlobalConfig().get_alias(cmd)
497
return alias.split(' ')
501
457
def run_bzr(argv):
502
458
"""Execute a command.
578
520
if not opt_no_plugins:
579
521
from bzrlib.plugin import load_plugins
582
from bzrlib.plugin import disable_plugins
587
if not opt_no_aliases:
588
alias_argv = get_alias(argv[0])
590
alias_argv = [a.decode(bzrlib.user_encoding) for a in alias_argv]
591
argv[0] = alias_argv.pop(0)
593
524
cmd = str(argv.pop(0))
595
526
cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
596
if not getattr(cmd_obj.run_argv, 'is_deprecated', False):
597
run = cmd_obj.run_argv
600
run = cmd_obj.run_argv_aliases
601
run_argv = [argv, alias_argv]
605
ret = apply_lsprofiled(opt_lsprof_file, run, *run_argv)
530
ret = apply_lsprofiled(cmd_obj.run_argv, argv)
606
531
elif opt_profile:
607
ret = apply_profiled(run, *run_argv)
532
ret = apply_profiled(cmd_obj.run_argv, argv)
534
ret = cmd_obj.run_argv(argv)
612
537
# reset, in case we may do other commands later within the same process