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 command %s'
326
% (a, command.name()))
329
if shortopt in Option.SHORT_OPTIONS:
330
# Multi-character options must have a space to delimit
332
# ^^^ what does this mean? mbp 20051014
333
optname = Option.SHORT_OPTIONS[shortopt].name
335
# Single character short options, can be chained,
336
# and have their value appended to their name
338
if shortopt not in Option.SHORT_OPTIONS:
339
# We didn't find the multi-character name, and we
340
# didn't find the single char name
341
raise BzrError('unknown short option %r' % a)
342
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:])
345
# There are extra things on this option
346
# see if it is the value, or if it is another
348
optargfn = Option.OPTIONS[optname].type
350
# This option does not take an argument, so the
351
# next entry is another short option, pack it back
353
proc_argv.insert(0, '-' + a[2:])
355
# This option takes an argument, so pack it
359
if optname not in cmd_options:
360
raise BzrOptionError('unknown short option %r for command'
361
' %s' % (shortopt, command.name()))
363
# XXX: Do we ever want to support this, e.g. for -r?
365
raise BzrError('repeated option %r' % a)
366
elif optname in alias_opts:
367
# Replace what's in the alias with what's in the real argument
368
del alias_opts[optname]
370
proc_argv.insert(0, a)
373
raise BzrError('repeated option %r' % a)
375
option_obj = cmd_options[optname]
376
optargfn = option_obj.type
380
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)
382
optarg = proc_argv.pop(0)
383
opts[optname] = optargfn(optarg)
385
alias_opts[optname] = optargfn(optarg)
388
raise BzrError('option %r takes no argument' % optname)
391
alias_opts[optname] = True
374
raise BzrError('option %r takes no argument' % optname)
394
proc_aliasarg = False # Done with alias argv
378
395
return args, opts
537
571
from bzrlib.plugin import disable_plugins
538
572
disable_plugins()
574
if not opt_no_aliases:
575
alias_argv = get_alias(argv[0])
577
alias_argv = [a.decode(bzrlib.user_encoding) for a in alias_argv]
578
argv[0] = alias_argv.pop(0)
540
580
cmd = str(argv.pop(0))
542
582
cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
546
ret = apply_lsprofiled(opt_lsprof_file, cmd_obj.run_argv, argv)
586
ret = apply_lsprofiled(opt_lsprof_file, cmd_obj.run_argv, argv, alias_argv)
547
587
elif opt_profile:
548
ret = apply_profiled(cmd_obj.run_argv, argv)
588
ret = apply_profiled(cmd_obj.run_argv, argv, alias_argv)
550
ret = cmd_obj.run_argv(argv)
590
ret = cmd_obj.run_argv(argv, alias_argv)
553
593
# reset, in case we may do other commands later within the same process