[Be-devel] BE reorganization

John Arbash Meinel john at arbash-meinel.com
Tue Jan 5 17:38:41 GMT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Barry Warsaw wrote:
> On Jan 05, 2010, at 11:56 AM, Gordon Tyler wrote:
> 
>> As far as I understand, it's not just an args parser, it's a whole
>> framework for the implementation of commands (e.g. bzr *commit*), and
>> the execution of those commands.
> 
> argparse supports subcommands quite nicely.  I've been using it in Mailman 3.
> 
> -Barry

Command also handles the dispatching to what sub-command. It also lets
you define a new subcommand by defining a class with specific attributes
(inheriting from Command).

I'm pretty sure that argparse follows the optparse model, of defining
the arguments by setting them onto a parser. I'm sure we could translate
the two. (Internally Command uses a fair bit of optparse to actually
parse the command line.)

But the basics of defining a new subcommand is:

class cmd_myfunc(Command):

  takes_args = ['always', 'maybe?', 'multiple+']
  takes_options = [Option('one', type=int, help='...')]

  def run(self, always, maybe=None, multiple_list=None, one=1):
    ...

register_command(cmd_myfunc)


And then if that subcommand is called, your class is instantiated, and
the run() method ends up getting called.

It also does stuff like "bzr help subcommand" knows to call the 'help()'
attribute of your class, etc.

I'm pretty sure that is quite a bit different to how argparse works.
Though honestly I haven't looked very closely.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAktDeSEACgkQJdeBCYSNAAOu3QCgnecpjo2T9bcjVXUldwCKwQPL
cw8AoKX2trdRcGGn1q6Q3LF15n63Ny67
=06hf
-----END PGP SIGNATURE-----



More information about the bazaar mailing list