211
@deprecated_method(zero_eight)
210
212
def run_argv(self, argv):
211
"""Parse command line and run."""
212
args, opts = parse_args(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)
213
222
if 'help' in opts: # e.g. bzr add --help
214
223
from bzrlib.help import help_on_command
215
224
help_on_command(self.name())
296
305
# TODO: chop up this beast; make it a method of the Command
300
310
cmd_options = command.options()
308
# We've received a standalone -- No more flags
312
# option names must not be unicode
316
mutter(" got option %r", a)
318
optname, optarg = a[2:].split('=', 1)
321
if optname not in cmd_options:
322
raise BzrOptionError('unknown long option %r for command %s'
323
% (a, command.name()))
326
if shortopt in Option.SHORT_OPTIONS:
327
# Multi-character options must have a space to delimit
329
# ^^^ what does this mean? mbp 20051014
330
optname = Option.SHORT_OPTIONS[shortopt].name
332
# Single character short options, can be chained,
333
# and have their value appended to their name
335
if shortopt not in Option.SHORT_OPTIONS:
336
# We didn't find the multi-character name, and we
337
# didn't find the single char name
338
raise BzrError('unknown short option %r' % a)
339
optname = Option.SHORT_OPTIONS[shortopt].name
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
342
# There are extra things on this option
343
# see if it is the value, or if it is another
345
optargfn = Option.OPTIONS[optname].type
347
# This option does not take an argument, so the
348
# next entry is another short option, pack it back
350
argv.insert(0, '-' + a[2:])
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
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)
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)
352
# This option takes an argument, so pack it
356
if optname not in cmd_options:
357
raise BzrOptionError('unknown short option %r for command'
358
' %s' % (shortopt, command.name()))
360
# XXX: Do we ever want to support this, e.g. for -r?
361
raise BzrError('repeated option %r' % a)
363
option_obj = cmd_options[optname]
364
optargfn = option_obj.type
368
raise BzrError('option %r needs an argument' % a)
371
opts[optname] = optargfn(optarg)
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
374
raise BzrError('option %r takes no argument' % optname)
406
proc_aliasarg = False # Done with alias argv
378
407
return args, opts
537
582
from bzrlib.plugin import disable_plugins
538
583
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)
540
593
cmd = str(argv.pop(0))
542
595
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]
546
ret = apply_lsprofiled(opt_lsprof_file, cmd_obj.run_argv, argv)
605
ret = apply_lsprofiled(opt_lsprof_file, run, *run_argv)
547
606
elif opt_profile:
548
ret = apply_profiled(cmd_obj.run_argv, argv)
607
ret = apply_profiled(run, *run_argv)
550
ret = cmd_obj.run_argv(argv)
553
612
# reset, in case we may do other commands later within the same process