The type of a config value depends on the tool that interprets it. Parsing eagerly can lead to a situation where we return a bool instead of a string or a number. Let the user specify the type themselves by passing in a (str, type) tuple into the mapping interface.
1.2 KiB
Configuration files
pygit2.Repository.config
The Config type
pygit2.Config.get_system_config
pygit2.Config.get_global_config
pygit2.Config.add_file
pygit2.Config.get_multivar
pygit2.Config.set_multivar
Config.__iter__()
The Config class
has an iterator which can be used to loop through all the entries in the
configuration. Each element is a tuple containing the name and the value
of each configuration variable. Be aware that this may return multiple
versions of each entry if they are set multiple times in the
configuration files.
The Config Mapping
interface.
Parsing the values
Instead of a string, a tuple of (str,type) can be used to look up a key and parse it through the Git rules. E.g.
config['core.bare',bool]
will return True if 'core.bare' is truthy.
Truty values are: 'true', 1, 'on' or 'yes'. Falsy values are: 'false', 0, 'off' and 'no'.
Available types are bool and int. Not specifying a type returns a string.