[PATCH]: Optional explanation for options
Robert Collins
robertc at robertcollins.net
Fri Sep 9 17:09:17 BST 2005
On Wed, 2005-09-07 at 09:04 +0100, Magnus Therning wrote:
> The following patch makes it possible to add explanations to options for
> commands. E.g.
>
> class cmd_my_command(Command):
> ...
> takes_options = [('revision', 'Retrieve particular revision')]
> ...
>
> I think it'd be handy for command line completion...
Ok, coming back to the patch...
> *** modified file 'bzrlib/help.py'
> --- bzrlib/help.py
> +++ bzrlib/help.py
> @@ -51,7 +51,7 @@
> """
>
>
> -import sys
> +import sys, types
>
>
> def help(topic=None, outfile = None):
> @@ -127,11 +127,18 @@
>
> outfile.write('\noptions:\n')
> for on in options:
> + if isinstance(on, types.TupleType):
> + expl = on[1]
> + on = on[0]
> + else:
> + expl = ''
This is somewhat ugly: an api where type inspection is needed is prone
to mistakes, and likely to have headaches. I think a better approach
would be to done something along the lines of this - which is wrong, but
demonstrates the concept:
Make the entries in OPTIONS a list of tuples with default explanations.
Then we get
class cmd_my_command(Command):
...
takes_options = [OPTIONS[option] for option in ['revision', ...]]
...
For commands that want to override:
class cmd_my_command(Command):
...
takes_options = [(OPTIONS['revision'][0], "foo bar does abc")]
...
The things that are wrong is that this is overly verbose and unclear.
Rob
--
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050910/a264623b/attachment.pgp
More information about the bazaar
mailing list