find_config Subroutine

public subroutine find_config(dir, cfg, stat, errmsg)

The configuration for files in directory dir (an absolute path): from the nearest config file in dir or its parents. cfg%path is '' if there is none.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: dir

absolute path of the directory

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

the configuration found

integer, intent(out) :: stat

nonzero if the config file found cannot be read

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

what is wrong, with the file name, if stat is nonzero


Calls

proc~~find_config~~CallsGraph proc~find_config find_config proc~empty empty proc~find_config->proc~empty proc~join_path join_path proc~find_config->proc~join_path proc~load_config load_config proc~find_config->proc~load_config proc~parent_directory parent_directory proc~find_config->proc~parent_directory proc~load_config->proc~empty 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~to_s to_s proc~load_config->proc~to_s toml_load toml_load proc~load_config->toml_load

Called by

proc~~find_config~~CalledByGraph proc~find_config find_config proc~config_for config_for proc~config_for->proc~find_config 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 find_config(dir, cfg, stat, errmsg)
    !! The configuration for files in directory `dir` (an absolute path): from the nearest config file
    !! in `dir` or its parents. `cfg%path` is `''` if there is none.
    character(len=*), intent(in) :: dir   !! absolute path of the directory
    type(config_t), intent(out) :: cfg   !! the configuration found
    integer, intent(out) :: stat                            !! nonzero if the config file found cannot be read
    character(len=:), allocatable, intent(out) :: errmsg    !! what is wrong, with the file name, if `stat` is nonzero
    character(len=:), allocatable :: d, candidate
    logical :: exists, found

    stat = 0
    d = dir
    do while (len(d) > 0)
        candidate = join_path(d, CONFIG_NAME)
        inquire (file=candidate, exist=exists)
        if (exists) then
            call load_config(candidate, .false., cfg, found, stat, errmsg)
            return
        end if
        candidate = join_path(d, 'fpm.toml')
        inquire (file=candidate, exist=exists)
        if (exists) then
            call load_config(candidate, .true., cfg, found, stat, errmsg)
            if (found .or. stat /= 0) return
        end if
        if (parent_directory(d) == d) exit
        d = parent_directory(d)
    end do
    call empty(cfg)
end subroutine find_config