class documentation

class FancyGetopt: (source)

View In Hierarchy

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_option Undocumented
Method generate_help Generate help text (a list of strings, one per suggested line of output) from the option table for this FancyGetopt object.
Method get_attr_name Translate long option name 'long_option' to the form it has as an attribute of some object: ie., translate hyphens to underscores.
Method get_option_order 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_option Return true if the option table for this parser has an option with long name 'long_option'.
Method print_help Undocumented
Method set_aliases Set the aliases for this option parser.
Method set_negative_aliases 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_option_table Undocumented
Instance Variable alias Undocumented
Instance Variable attr_name Undocumented
Instance Variable long_opts Undocumented
Instance Variable negative_alias Undocumented
Instance Variable option_index Undocumented
Instance Variable option_order Undocumented
Instance Variable option_table Undocumented
Instance Variable repeat Undocumented
Instance Variable short2long Undocumented
Instance Variable short_opts Undocumented
Instance Variable takes_arg Undocumented
Method _build_index Undocumented
Method _check_alias_dict Undocumented
Method _grok_option_table Populate the various data structures that keep tabs on the option table. Called by 'getopt()' before it can do anything worthwhile.
def __init__(self, option_table=None): (source)

Undocumented

def add_option(self, long_option, short_option=None, help_string=None): (source)

Undocumented

def generate_help(self, header=None): (source)

Generate help text (a list of strings, one per suggested line of output) from the option table for this FancyGetopt object.

def get_attr_name(self, long_option): (source)

Translate long option name 'long_option' to the form it has as an attribute of some object: ie., translate hyphens to underscores.

def get_option_order(self): (source)

Returns the list of (option, value) tuples processed by the previous run of 'getopt()'. Raises RuntimeError if 'getopt()' hasn't been called yet.

def getopt(self, args=None, object=None): (source)

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.

def has_option(self, long_option): (source)

Return true if the option table for this parser has an option with long name 'long_option'.

def print_help(self, header=None, file=None): (source)

Undocumented

def set_aliases(self, alias): (source)

Set the aliases for this option parser.

def set_negative_aliases(self, negative_alias): (source)

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.

def set_option_table(self, option_table): (source)

Undocumented

Undocumented

attr_name: dict = (source)

Undocumented

long_opts: list = (source)

Undocumented

negative_alias = (source)

Undocumented

option_index: dict = (source)

Undocumented

option_order: list = (source)

Undocumented

option_table = (source)

Undocumented

Undocumented

short2long: dict = (source)

Undocumented

short_opts: list = (source)

Undocumented

takes_arg: dict = (source)

Undocumented

def _build_index(self): (source)

Undocumented

def _check_alias_dict(self, aliases, what): (source)

Undocumented

def _grok_option_table(self): (source)

Populate the various data structures that keep tabs on the option table. Called by 'getopt()' before it can do anything worthwhile.