예제 #1
0
def config_file_decorator():
    return click_config_file.configuration_option(
        default=LOCAL_CONFIG_FILENAME,
        implicit=False,
        provider=load_commands_config,
        hidden=True,
    )
예제 #2
0
 def _add_config_file_support(func):
     config_file_path = _get_global_config_path()
     option = click_config_file.configuration_option(
         implicit=True,
         provider=_click_load_config,
         config_file_name=config_file_path,
     )
     return option(func)
예제 #3
0
    def __call__(self, **kwargs):
        """
        Override the stored kwargs, (ignoring args as we do not allow option name changes) and return the option.

        :param kwargs: keyword arguments that will override those set in the construction
        :return: click_config_file.configuration_option constructed with args and kwargs defined during construction
            and call of this instance
        """
        kw_copy = self.kwargs.copy()
        kw_copy.update(kwargs)

        return click_config_file.configuration_option(*self.args, **kw_copy)
예제 #4
0
def yaml_config_option():
    path = os.path.join(platformdirs.user_config_dir(appname=__package__),
                        'config.yaml')

    def provider(file_path, _cmd_name):
        if os.path.isfile(file_path):
            with open(file_path) as f:
                return yaml.safe_load(f)
        else:
            return {}

    return click_config_file.configuration_option(implicit=False,
                                                  default=path,
                                                  show_default=True,
                                                  provider=provider)