confight icon indicating copy to clipboard operation
confight copied to clipboard

Support custom formats

Open jvrsantacruz opened this issue 1 year ago • 0 comments

Allows to register custom formats fixes #26 by also changing the file loader API to control how the stream is created.

Other formats can be registered by name providing a function with the loader signature loader(path): dict and registering using the register_format function.

from confight import register_loader, register_extension

def load_assign(path):
    """Parse files with KEY=VALUE lines """
    with open(path, 'r') as stream:
        return dict(line.split('=', 1) for line in stream]

register_loader('equal', load_assign)

Extensions can also be associated to previously registered formats by adding them to the extension register as alias so it automatically detects with .eq extension:

register_extension('eq', format='equal')

jvrsantacruz avatar May 28 '24 06:05 jvrsantacruz