Recommended way for plugin to add an option to an existing command?

vila v.ladeuil+lp at free.fr
Sat Mar 19 11:13:21 UTC 2011


>>>>> Neil Martinsen-Burrell <nmb at wartburg.edu> writes:

    > What is the recommended way to add an option to an existing command
    > from a plugin?  I know that there are numerous plugins that do this,
    > and I seem to remember a discussion about wanting to add a standard
    > way to do so, but I'm not sure what the current state of the art is.
    > How can I add an option to a command whose value I would like to use
    > to supplement the behavior of an existing command?

    > What I would like to do is define a template LogFormatter.  Ideally, I
    > would do "bzr log --log-format=template --template-str='{revno}
    > {author}'".  I can define the LogFormatter in my plugin, but I don't
    > know the right way to inject my option onto the log command.  With the
    > way that cmd_log works currently, I have to get the value of
    > template-str and use that to construct an appropriate parametrized
    > LogFormatter class that can then be passed to the original run()
    > method of the log command.  What is the right way to add that option?

    > Any help is welcome.

Well, in this case I would try to *avoid* adding an option to the
command but instead make the log formatter get the template from a
config option.

You'll lose the ability to specify the template from the command line
(but see below) but you'll gain the ability to set it in any config file
(branch.conf, bazaar.conf, locations.conf).

With recent versions of bzr you can also use the config.expand_options()
method and pass it a string (your template) and a dict containing
whatever you see fit (revno, author, etc) in the 'env' parameter.

There is also bug #491196 which, once fixed, will finally allow you to
specify the template from the command line.

If you want more insight about what is cooking for config files, have a
look at: http://doc.bazaar.canonical.com/devnotes/configuration.html

Hth,

        Vincent



More information about the bazaar mailing list