Coder Social home page Coder Social logo

Comments (4)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
I don't think that allowing the main parser options interspersed with the 
subparser
options is right for all applications. For example, while 'svn --version' 
works, 'svn
co --version' doesn't. So at least SVN has decided that --version is not a 
global option.

Right now, the only real way to use global options is to store all your global
options in one parser, and then add those options to all your subparsers using 
the
parser= keyword argument to the ArgumentParser constructor. Something like this:

>>> global_options = argparse.ArgumentParser(add_help=False)
>>> global_options.add_argument('--bar', action='store_true')
>>> parser = argparse.ArgumentParser(parents=[global_options])
>>> subparsers = parser.add_subparsers()
>>> parser1 = subparsers.add_parser('1', parents=[global_options])
>>> parser.parse_args(['--bar', '1'])
Namespace(bar=True)
>>> parser.parse_args(['1', '--bar'])
Namespace(bar=True)

I'm open to patches which make it easier to specify global options if you have
specific ideas.

Original comment by [email protected] on 8 Sep 2009 at 1:11

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024

Original comment by [email protected] on 8 Sep 2009 at 1:11

  • Changed state: Accepted
  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
s/using the parser= keyword/using the parents= keyword/

Original comment by [email protected] on 10 Sep 2009 at 3:41

from argparse.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 23, 2024
Closing this as the parents keyword allows the desired behavior to be requested 
explicitly. If you'd like to propose an API for this, please either discuss on 
the argarse users list, or file a feature request on bugs.python.org.

Original comment by [email protected] on 23 Jul 2010 at 10:53

  • Changed state: WontFix

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.