class FancyGetopt: (source)
Wrapper around the standard 'getopt()' module that provides some handy extra functionality: * short and long options are tied together * options have help strings, and help text can be assembled from them * options set attributes of a passed-in object * boolean options can have "negative aliases" -- eg. if --quiet is the "negative alias" of --verbose, then "--quiet" on the command line sets 'verbose' to false
Method | __init__ |
Undocumented |
Method | add |
Undocumented |
Method | generate |
Generate help text (a list of strings, one per suggested line of output) from the option table for this FancyGetopt object. |
Method | get |
Translate long option name 'long_option' to the form it has as an attribute of some object: ie., translate hyphens to underscores. |
Method | get |
Returns the list of (option, value) tuples processed by the previous run of 'getopt()'. Raises RuntimeError if 'getopt()' hasn't been called yet. |
Method | getopt |
Parse command-line options in args. Store as attributes on object. |
Method | has |
Return true if the option table for this parser has an option with long name 'long_option'. |
Method | print |
Undocumented |
Method | set |
Set the aliases for this option parser. |
Method | set |
Set the negative aliases for this option parser. 'negative_alias' should be a dictionary mapping option names to option names, both the key and value must already be defined in the option table. |
Method | set |
Undocumented |
Instance Variable | alias |
Undocumented |
Instance Variable | attr |
Undocumented |
Instance Variable | long |
Undocumented |
Instance Variable | negative |
Undocumented |
Instance Variable | option |
Undocumented |
Instance Variable | option |
Undocumented |
Instance Variable | option |
Undocumented |
Instance Variable | repeat |
Undocumented |
Instance Variable | short2long |
Undocumented |
Instance Variable | short |
Undocumented |
Instance Variable | takes |
Undocumented |
Method | _build |
Undocumented |
Method | _check |
Undocumented |
Method | _grok |
Populate the various data structures that keep tabs on the option table. Called by 'getopt()' before it can do anything worthwhile. |
Generate help text (a list of strings, one per suggested line of output) from the option table for this FancyGetopt object.
Translate long option name 'long_option' to the form it has as an attribute of some object: ie., translate hyphens to underscores.
Returns the list of (option, value) tuples processed by the previous run of 'getopt()'. Raises RuntimeError if 'getopt()' hasn't been called yet.
Parse command-line options in args. Store as attributes on object. If 'args' is None or not supplied, uses 'sys.argv[1:]'. If 'object' is None or not supplied, creates a new OptionDummy object, stores option values there, and returns a tuple (args, object). If 'object' is supplied, it is modified in place and 'getopt()' just returns 'args'; in both cases, the returned 'args' is a modified copy of the passed-in 'args' list, which is left untouched.