272
272
if self.__doc__ == Command.__doc__:
273
273
warn("No help message set for %r" % self)
276
def run_argv(self, argv):
277
"""Parse command line and run."""
278
args, opts = parse_args(argv)
280
if 'help' in opts: # e.g. bzr add --help
281
from bzrlib.help import help_on_command
282
help_on_command(self.name())
285
# check options are reasonable
286
allowed = self.takes_options
288
if oname not in allowed:
289
raise BzrCommandError("option '--%s' is not allowed for command %r"
290
% (oname, self.name()))
292
# mix arguments and options into one dictionary
293
cmdargs = _match_argform(self.name(), self.takes_args, args)
295
for k, v in opts.items():
296
cmdopts[k.replace('-', '_')] = v
298
all_cmd_args = cmdargs.copy()
299
all_cmd_args.update(cmdopts)
301
return self.run(**all_cmd_args)
277
305
"""Actually run the command.
619
if (not argv) or (argv[0] == '--help'):
620
from bzrlib.help import help
627
if argv[0] == '--version':
628
from bzrlib.builtins import show_version
591
632
if not opt_no_plugins:
592
633
from bzrlib.plugin import load_plugins
595
args, opts = parse_args(argv)
598
from bzrlib.help import help
605
if 'version' in opts:
606
from bzrlib.builtins import show_version
611
from bzrlib.help import help
615
cmd = str(args.pop(0))
636
cmd = str(argv.pop(0))
617
638
cmd_obj = get_cmd_object(cmd, plugins_override=not opt_builtin)
619
# check options are reasonable
620
allowed = cmd_obj.takes_options
622
if oname not in allowed:
623
raise BzrCommandError("option '--%s' is not allowed for command %r"
626
# mix arguments and options into one dictionary
627
cmdargs = _match_argform(cmd, cmd_obj.takes_args, args)
629
for k, v in opts.items():
630
cmdopts[k.replace('-', '_')] = v
632
all_cmd_args = cmdargs.copy()
633
all_cmd_args.update(cmdopts)
636
ret = apply_profiled(cmd_obj.run, **all_cmd_args)
641
ret = apply_profiled(cmd_obj.run_argv, argv)
638
ret = cmd_obj.run(**all_cmd_args)
643
ret = cmd_obj.run_argv(argv)