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.
| Type | Intent | Optional | 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 |
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