296
296
# TODO: chop up this beast; make it a method of the Command
300
301
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
303
proc_aliasarg = True # Are we processing alias_argv now?
304
for proc_argv in alias_argv, argv:
311
# We've received a standalone -- No more flags
315
# option names must not be unicode
319
mutter(" got option %r", a)
321
optname, optarg = a[2:].split('=', 1)
324
if optname not in cmd_options:
325
raise BzrOptionError('unknown long option %r for'
330
if shortopt in Option.SHORT_OPTIONS:
331
# Multi-character options must have a space to delimit
333
# ^^^ what does this mean? mbp 20051014
334
optname = Option.SHORT_OPTIONS[shortopt].name
336
# Single character short options, can be chained,
337
# and have their value appended to their name
339
if shortopt not in Option.SHORT_OPTIONS:
340
# We didn't find the multi-character name, and we
341
# didn't find the single char name
342
raise BzrError('unknown short option %r' % a)
343
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:])
346
# There are extra things on this option
347
# see if it is the value, or if it is another
349
optargfn = Option.OPTIONS[optname].type
351
# This option does not take an argument, so the
352
# next entry is another short option, pack it
354
proc_argv.insert(0, '-' + a[2:])
356
# This option takes an argument, so pack it
360
if optname not in cmd_options:
361
raise BzrOptionError('unknown short option %r for'
363
(shortopt, command.name()))
365
# XXX: Do we ever want to support this, e.g. for -r?
367
raise BzrError('repeated option %r' % a)
368
elif optname in alias_opts:
369
# Replace what's in the alias with what's in the real
371
del alias_opts[optname]
373
proc_argv.insert(0, a)
376
raise BzrError('repeated option %r' % a)
378
option_obj = cmd_options[optname]
379
optargfn = option_obj.type
383
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)
385
optarg = proc_argv.pop(0)
386
opts[optname] = optargfn(optarg)
388
alias_opts[optname] = optargfn(optarg)
391
raise BzrError('option %r takes no argument' % optname)
394
alias_opts[optname] = True
374
raise BzrError('option %r takes no argument' % optname)
397
proc_aliasarg = False # Done with alias argv
378
398
return args, opts
537
574
from bzrlib.plugin import disable_plugins
538
575
disable_plugins()
577
if not opt_no_aliases:
578
alias_argv = get_alias(argv[0])
580
alias_argv = [a.decode(bzrlib.user_encoding) for a in alias_argv]
581
argv[0] = alias_argv.pop(0)
540
583
cmd = str(argv.pop(0))
542
585
cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
546
ret = apply_lsprofiled(opt_lsprof_file, cmd_obj.run_argv, argv)
589
ret = apply_lsprofiled(opt_lsprof_file, cmd_obj.run_argv, argv,
547
591
elif opt_profile:
548
ret = apply_profiled(cmd_obj.run_argv, argv)
592
ret = apply_profiled(cmd_obj.run_argv, argv, alias_argv)
550
ret = cmd_obj.run_argv(argv)
594
ret = cmd_obj.run_argv(argv, alias_argv)
553
597
# reset, in case we may do other commands later within the same process