config_for Subroutine

private subroutine config_for(cli, cache, dir, cfg, stat, errmsg)

The configuration that applies in directory dir (absolute).

Arguments

Type IntentOptional Attributes Name
type(cli_t), intent(in) :: cli

the parsed command line (--config, --no-config)

type(config_cache_t), intent(inout) :: cache

configurations found so far; cfg is added

character(len=*), intent(in) :: dir

absolute path of the directory

type(config_t), intent(out) :: cfg

the configuration; cfg%path is '' if there is none

integer, intent(out) :: stat

nonzero if a configuration file cannot be read

character(len=:), intent(out), allocatable :: errmsg

what is wrong, if stat is nonzero


Calls

proc~~config_for~~CallsGraph proc~config_for config_for proc~ends_with ends_with proc~config_for->proc~ends_with proc~find_config find_config proc~config_for->proc~find_config proc~load_config load_config proc~config_for->proc~load_config proc~find_config->proc~load_config proc~empty empty proc~find_config->proc~empty proc~join_path join_path proc~find_config->proc~join_path proc~parent_directory parent_directory proc~find_config->proc~parent_directory get get proc~load_config->get get_keys get_keys proc~load_config->get_keys get_type get_type proc~load_config->get_type get_value get_value proc~load_config->get_value proc~load_config->proc~empty proc~to_s to_s proc~load_config->proc~to_s toml_load toml_load proc~load_config->toml_load

Called by

proc~~config_for~~CalledByGraph proc~config_for config_for proc~directory_files directory_files proc~directory_files->proc~config_for proc~options_for options_for proc~options_for->proc~config_for proc~process_text process_text proc~process_text->proc~options_for proc~run run proc~run->proc~directory_files proc~process_file process_file proc~run->proc~process_file proc~process_stdin process_stdin proc~run->proc~process_stdin proc~process_file->proc~process_text proc~process_stdin->proc~process_text

Source Code

subroutine config_for(cli, cache, dir, cfg, stat, errmsg)
    !! The configuration that applies in directory `dir` (absolute).
    type(cli_t), intent(in) :: cli                          !! the parsed command line (`--config`, `--no-config`)
    type(config_cache_t), intent(inout) :: cache            !! configurations found so far; `cfg` is added
    character(len=*), intent(in) :: dir   !! absolute path of the directory
    type(config_t), intent(out) :: cfg                      !! the configuration; `cfg%path` is `''` if there is none
    integer, intent(out) :: stat                            !! nonzero if a configuration file cannot be read
    character(len=:), allocatable, intent(out) :: errmsg    !! what is wrong, if `stat` is nonzero
    logical :: found
    integer :: k

    stat = 0
    if (cli%no_config) then
        cfg%path = ''
        allocate (cfg%settings(0))
        return
    end if
    if (len(cli%config) > 0) then
        call load_config(cli%config, ends_with(cli%config, 'fpm.toml'), cfg, found, stat, errmsg)
        if (stat == 0 .and. .not. found) then
            stat = 1
            errmsg = cli%config//': no [extra.fformat] table'
        end if
        return
    end if
    do k = 1, size(cache%dirs)
        if (cache%dirs(k)%s == dir .and. len(cache%dirs(k)%s) == len(dir)) then
            cfg = cache%configs(k)
            return
        end if
    end do
    call find_config(dir, cfg, stat, errmsg)
    if (stat /= 0) return
    cache%dirs = [cache%dirs, string_t(dir)]
    cache%configs = [cache%configs, cfg]
end subroutine config_for