Adding options to commands

Martin Pool mbp at canonical.com
Thu Jun 5 03:11:09 BST 2008


On Thu, Jun 5, 2008 at 7:20 AM, Russ Brown <pickscrape at gmail.com> wrote:
> I was just looking at getting the diffstat pluging to add a --stat
> option to the diff command, and so needed to know how to add options to
> an existing command.
>
> For an example I was pointed at the xml-output plugin, which adds
> options to a number of builtin commands.
>
> Looking at the code, it seems the additional options are added by
> subclassing the builtin command handler.
>
> This made me wonder what happens if more than one plugin wants to add
> options to the same builtin command. Does this magically work, or is it
> a limitation of the plugin system?

I don't think it will work if they both subclass the builtin command.
It seems to me they'd be better off asking for the command currently
registered under that name (through get_cmd_object) and wrapping that.
 Then they'll wrap each other in whichever order they register.  (Of
course it's possible you'll have some bad interactions if they want to
do contradictory things but that's a separate issue...)

If this works for you maybe you could add a note on the wiki in
http://bazaar-vcs.org/WritingPlugins

-- 
Martin <http://launchpad.net/~mbp/>



More information about the bazaar mailing list