2.4 Groups

The add_option_group() method can be used to create groups of options. The purpose of grouping options is strictly for organizing the help text to make it more presentable to the user.

add_option_group( title[ ,description])

title is a required positional string argument and generally is a few words used to label the configuration option group.

description is an optional keyword argument and can be used to provide a more lengthy description of the configuration option group.

add_option_group() returns an instance of the OptionGroup class which has the same add_option() method as the parser.

For example:

import cfgparse
c = cfgparse.ConfigParser()
c.add_option('opt0', help='Help for opt0')

group = c.add_option_group('Group 1')
group.add_option('opt1', help='Help for opt1')

group = c.add_option_group('Group 2','Some long winded discussion about '
    'group 2 that will not fit all on a single line if that single line '
    'is not extremely wide.')
group.add_option('opt2', help='Help for opt2')

c.print_help()

Results in:

$ python groups.py
Configuration file options:
  opt0=OPT0    Help for opt0

  Group 1:
    opt1=OPT1  Help for opt1

  Group 2:
    Some long winded discussion about group 2 that will not fit all on a
    single line if that single line is not extremely wide.

    opt2=OPT2  Help for opt2