kdeldycke/click-extra

How can I load a dotfile as a config file?

yamaton opened this issue · 5 comments

Hello.

When I want to load a dotfile-style config file (such as .bashrc) in YAML, how can I specify the file format? It appears click-extra selects the parser from the file extension. Is there a way to handle dotfiles?

Thanks for open sourcing your project!

Oh good point. This makes sense. I'll try to find a way to allow for setting the expected configuration file format instead of relying on auto-detection based on file extension.

I just refactored the way configuration file and formats are handled. That way we do not rely anymore on the file extension to guess the dialect the configuration file is written in, addressing your use case.

This change has been committed upstream will be available in the upcoming v3.1.0 release of click-extra.

Hey @yamaton, I just updated the documentation to cover your use-case at: https://kdeldycke.github.io/click-extra/config.html#custom-pattern

All in all, you can now address your use-case with the following decorator:

from click import command

from click_extra import config_option
from click_extra.config import Formats

@command(context_settings={"show_default": True})
@config_option(default="~/.bashrc", formats=Formats.YAML)
def cli():
    pass

Which produce the following help screen:

$ cli --help
Usage: cli [OPTIONS]

Options:
  -C, --config CONFIG_PATH  Location of the configuration file. Supports glob
                            pattern of local path and remote URL.  [default:
                            ~/.bashrc]
  --help                    Show this message and exit.

@kdeldycke Awesome! Thank you so much for your continued effort.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.