1668
def _parse_master_args(argv):
1669
"""Parse the arguments that always go with the original command.
1670
These are things like bzr --no-plugins, etc.
1672
There are now 2 types of option flags. Ones that come *before* the command,
1673
and ones that come *after* the command.
1674
Ones coming *before* the command are applied against all possible commands.
1675
And are generally applied before plugins are loaded.
1677
The current list are:
1678
--builtin Allow plugins to load, but don't let them override builtin commands,
1679
they will still be allowed if they do not override a builtin.
1680
--no-plugins Don't load any plugins. This lets you get back to official source
1682
--profile Enable the hotspot profile before running the command.
1683
For backwards compatibility, this is also a non-master option.
1684
--version Spit out the version of bzr that is running and exit.
1685
This is also a non-master option.
1686
--help Run help and exit, also a non-master option (I think that should stay, though)
1688
>>> argv, opts = _parse_master_args(['--test'])
1689
Traceback (most recent call last):
1691
BzrCommandError: Invalid master option: 'test'
1692
>>> argv, opts = _parse_master_args(['--version', 'command'])
1695
>>> print opts['version']
1697
>>> argv, opts = _parse_master_args(['--profile', 'command', '--more-options'])
1699
['command', '--more-options']
1700
>>> print opts['profile']
1702
>>> argv, opts = _parse_master_args(['--no-plugins', 'command'])
1705
>>> print opts['no-plugins']
1707
>>> print opts['profile']
1709
>>> argv, opts = _parse_master_args(['command', '--profile'])
1711
['command', '--profile']
1712
>>> print opts['profile']
1715
master_opts = {'builtin':False,
1723
if arg[:2] != '--': # at the first non-option, we return the rest
1725
arg = arg[2:] # Remove '--'
1726
if arg not in master_opts:
1727
# We could say that this is not an error, that we should
1728
# just let it be handled by the main section instead
1729
raise BzrCommandError('Invalid master option: %r' % arg)
1730
argv.pop(0) # We are consuming this entry
1731
master_opts[arg] = True
1732
return argv, master_opts
1736
1669
def run_bzr(argv):
1737
1670
"""Execute a command.
1740
1673
logging and error handling.
1743
The command-line arguments, without the program name.
1676
The command-line arguments, without the program name from argv[0]
1745
1678
Returns a command status or raises an exception.
1680
Special master options: these must come before the command because
1681
they control how the command is interpreted.
1684
Do not load plugin modules at all
1687
Only use builtin commands. (Plugins are still allowed to change
1691
Run under the Python profiler.
1747
1694
argv = [a.decode(bzrlib.user_encoding) for a in argv]
1749
# some options like --builtin and --no-plugins have special effects
1750
argv, master_opts = _parse_master_args(argv)
1751
if not master_opts['no-plugins']:
1696
opt_profile = opt_no_plugins = opt_builtin = False
1698
# --no-plugins is handled specially at a very early stage. We need
1699
# to load plugins before doing other command parsing so that they
1700
# can override commands, but this needs to happen first.
1703
if a == '--profile':
1705
elif a == '--no-plugins':
1706
opt_no_plugins = True
1707
elif a == '--builtin':
1713
if not opt_no_plugins:
1752
1714
from bzrlib.plugin import load_plugins
1755
1717
args, opts = parse_args(argv)
1757
if master_opts.get('help') or 'help' in opts:
1758
1720
from bzrlib.help import help
1769
if args and args[0] == 'builtin':
1770
include_plugins=False
1774
cmd = str(args.pop(0))
1776
1732
print >>sys.stderr, "please try 'bzr help' for help"
1779
plugins_override = not (master_opts['builtin'])
1780
canonical_cmd, cmd_class = get_cmd_class(cmd, plugins_override=plugins_override)
1782
profile = master_opts['profile']
1783
# For backwards compatibility, I would rather stick with --profile being a
1784
# master/global option
1785
if 'profile' in opts:
1735
cmd = str(args.pop(0))
1737
canonical_cmd, cmd_class = \
1738
get_cmd_class(cmd, plugins_override=not opt_builtin)
1789
1740
# check options are reasonable
1790
1741
allowed = cmd_class.takes_options