Skip to content

Instantly share code, notes, and snippets.

@ErinCall
Created August 5, 2012 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ErinCall/3261804 to your computer and use it in GitHub Desktop.
Save ErinCall/3261804 to your computer and use it in GitHub Desktop.
I have two parsers: one looks at sys.argv while the other looks at some of the tokens the first slurped up. So from argparse's perspective, it does seem like there should just be one parser. I assert that isn't appropriate for my purposes, though:
The first parser is looking at general lay-of-the-land-type stuff: "username to use when calling that API", etc.
The second is looking at specific what-to-do stuff: "what you should do with that API."
I want the settings for the first part to be configurable in a couple different ways: config file, env vars, command-line arguments. For that, I really want my various "configuration getters" to live together. The "what to do" parser has no business in that domain, though; I want it at the top-level script where it can determine a dispatch to some library function. So I have two parsers.
All I'm trying to get argparse to do is "if you are displaying a usage message, display the message for the general script and also the one describing the various subparsers." sys.exit is making that desire really hard to attain!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment