Default for ListOption

Martin von Gagern Martin.vGagern at gmx.net
Tue Apr 20 13:14:38 BST 2010


Hi there!

Currently ListOption has a default of [], so if you have an option --bar
to a command foo, the command cannot easily (i.e. without custom
callback function) distinguish between invocation "foo" and invocation
"foo --bar=baz --bar=-", as both of these result in the empty list.

I consider this a wee bit ugly, in particular in cases where not
specifying a value has the meaning of "all possible values". I wonder
whether it would be better to handle the case of no option at all by not
including a corresponding value in the command's kwargs, thereby falling
back to its default value from the method declaration. That would be
consistent with other options, that fall back to method defaults as well.

I know that this would introduce a deliberate distinction between not
passing "--bar" at all and passing "--bar=-". Do you think this is a
good idea? If not, "--bar=-" might imply "use default" as well, and a
new "--no-bar" option might provide a way to explicitely request an
empty list.

I also know that this change might break plugins which always assume the
value of a ListOption to be a list, and perhaps don't even provide a
default value at all. How serious do you consider this impact? If this
would break too much, maybe an additional argument to the ListOption
constructor would be in order, which controls both the "--no-bar" style
option and the use of a default value.

The scenario that brought me to this is the following: For the
bzr-bash-completion plugin I was adding an option to control the list of
plugins from which commands should be included. No selection should mean
no restriction, i.e. all plugins, but it would be nice if I could use a
related syntax to specifcally request "no plugins at all".

This mail is a spin-off from a comment I wrote in my merge request
https://code.launchpad.net/~gagern/bzr/bug387117/+merge/23750

Greetings,
 Martin von Gagern

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20100420/315d7e7e/attachment.pgp 


More information about the bazaar mailing list