Skip to content

Instantly share code, notes, and snippets.

View vogonistic's full-sized avatar

Kent Karlsson vogonistic

  • Vistträsk, Sweden
  • 13:35 (UTC +02:00)
View GitHub Profile
@vogonistic
vogonistic / subcommand.py
Created August 31, 2012 16:19 — forked from sampsyo/subcommand.py
subcommand support for Python's optparse
"""A simple addition to Python's optparse module supporting subcommands
like those found in the svn or hg CLIs.
To use it, instantiate the Subcommand class for every subcommand you
want to support. Each subcommand has a name, aliases, a help message,
and a separate OptionParser instance. Then pass a list of Subcommands
to the constructor of SubcommandsOptionParser to make a subcommand-
aware parser. Calling parse_args on that parser gives you the
subcommand invoked, the subcommand's arguments and options, and the
global options all in one fell swoop. See the smoke test at the bottom