[Python-Dev] Python 2.7b1 and argparse's version action

Steven Bethard steven.bethard at gmail.com
Mon Apr 19 06:22:06 CEST 2010


On Sun, Apr 18, 2010 at 4:35 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Steven Bethard wrote:
>> On Sun, Apr 18, 2010 at 3:57 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>> Steven Bethard wrote:
>>>> By the way, we could simplify the typical add_argument usage by adding
>>>> "show program's version number and exit" as the default help for the
>>>> 'version' action. Then you should just write:
>>>>
>>>>     parser.add_argument('--version', action='version', version='<the version>')
>>> With that change, I would have no problem with the current argparse
>>> behaviour (since doing it this way makes it very easy for people to add
>>> a "-V" shortcut if they want one).
>>
>> Probably this should happen regardless of the outcome of the
>> constructor argument. The only reason it wasn't already there is that
>> I hadn't thought of it. ;-)
>
> Crazy thought... would it make sense to have the following implicitly
> use "--version" as the option flag:
>
>  parser.add_argument(action='version', version='<details>')

It would be possible, but not simple. The main drawback is that it
would have to be done in the parser code, and not in the VersionAction
class where all the other version behavior is. I think it's not a huge
gain over supplying the option strings, particularly if you're
following, say, the Python executable conventions:

  parser.add_argument('-V', action='version', version='<details>')

Steve
-- 
Where did you get that preposterous hypothesis?
Did Steve tell you that?
        --- The Hiphopopotamus


More information about the Python-Dev mailing list