Default for ListOption

Martin Pool mbp at canonical.com
Wed Apr 21 01:45:17 BST 2010


On 20 April 2010 22:14, Martin von Gagern <Martin.vGagern at gmx.net> wrote:
> 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.

You can't specify a default in the ListOption?
>
> 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 don't think that's a good idea; for things like aliases or shell
scripting it seems a bit useful for --bar=- to mean "forget I ever
mentioned bar".  So --no-bar is perhaps the easiest for users and
shouldn't break the api.

Some other programs seem to handle this with --bar=none though that's
a bit ugly with None vs 'none'.


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



More information about the bazaar mailing list