Optional arguments
Martin Pool
mbp at canonical.com
Fri Jul 14 02:28:38 BST 2006
On 12 Jul 2006, Aaron Bentley <aaron.bentley at utoronto.ca> wrote:
> On a related note:
>
> I've got a command (bzrtools shove) that would like to do
> TAKES_ARGS=['source?', 'target']
>
> The behaviour would be:
>
> [] => ERROR
> ['TAR'] => {'target': 'TAR'}
> ['SRC', 'TAR'] => {source:'SRC', target:'TAR'}
>
> Do you think that permitting optional arguments to occur before required
> arguments makes sense? I've currently solved this by taking arguments
> in the reverse order: takes_args = ['target', 'source?'], but this isn't
> intuitive since it's different from commands such as branch.
>
> The other option would be to change the command, so that you can omit an
> argument when it's run in the target directory, not the source.
I think it's reasonable to support such a syntax; there are other
commands that give a precedent. There is already support in
_match_argform for an argument that repeats at least one, but not the
last argument. So you could add one like that.
--
Martin
More information about the bazaar
mailing list