Giter Club home page Giter Club logo

Comments (5)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 12, 2024
If you don't like the default version argument, you should supply your own, 
e.g.:

>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('-V', action='version')
>>> parser.version = 'foo 0.1'
>>> parser.add_argument('-v', '--verbose')
>>> parser.parse_args(['-V'])
foo 0.1

The only thing that's a little odd about this solution is that you can't 
specify the
version in the add_argument call. Ideally I think you'd write:

>>> parser.add_argument('-V', action='version', version='foo 0.1')

If this would meet your needs, I'll see about a patch. In the meantime, you can 
use
the above workaround.

Original comment by [email protected] on 17 Aug 2009 at 6:16

  • Changed state: Accepted

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 12, 2024
Indeed, I am using:

>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('-V', '--version', ...)
>>> parser.add_argument('-v', '--verbose', ...)
...

It wasn't immediately obvious to do:

>>> parser.add_argument('-V', action='version')
>>> parser.version = 'foo 0.1'

but that works quite well.  I don't think I need anything further, but you could
still consider a small change to code or documentation to make it obvious how to
configure version.

Thanks

Original comment by [email protected] on 17 Aug 2009 at 6:27

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 12, 2024
Yep, if nothing else, I'll add some documentation.

Original comment by [email protected] on 17 Aug 2009 at 6:30

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 12, 2024
Thinking about this a bit, I believe the right answer is definitely to modify
_VersionAction to take a version= argument so that this works:

>>> parser.add_argument('-V', action='version', version='foo 0.1')

I'm changing this ticket to a feature enhancement because I can't really 
justify that
change as a bugfix, but this is an easy feature to add, and I'll definitely 
include
it in the 1.1 release.

Original comment by [email protected] on 12 Sep 2009 at 4:19

  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 12, 2024
Added in r68. The following now works:

>>> parser = argparse.ArgumentParser(prog='PROG')
>>> parser.add_argument('-V', action='version', version='%(prog)s 2.0')
>>> parser.parse_args(['-V'])
PROG 2.0

Original comment by [email protected] on 24 Oct 2009 at 4:54

  • Changed state: Fixed

from argparse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.