options_for Subroutine

private subroutine options_for(cli, cache, dir, opts, stat, errmsg)

The options for a file in directory dir: defaults, then configuration, then command line.

Arguments

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

the parsed command line

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

configurations found so far

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

the file's directory, relative or absolute

type(format_options_t), intent(out) :: opts

the options

integer, intent(out) :: stat

nonzero for an unreadable configuration or a bad setting

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

what is wrong, if stat is nonzero


Calls

proc~~options_for~~CallsGraph proc~options_for options_for proc~absolute_path absolute_path proc~options_for->proc~absolute_path proc~apply_setting apply_setting proc~options_for->proc~apply_setting proc~config_for config_for proc~options_for->proc~config_for proc~current_directory current_directory proc~absolute_path->proc~current_directory proc~is_absolute is_absolute proc~absolute_path->proc~is_absolute proc~join_path join_path proc~absolute_path->proc~join_path proc~to_s to_s proc~apply_setting->proc~to_s 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 interface~c_getcwd c_getcwd proc~current_directory->interface~c_getcwd proc~find_config->proc~join_path proc~find_config->proc~load_config proc~empty empty proc~find_config->proc~empty proc~parent_directory parent_directory proc~find_config->proc~parent_directory proc~load_config->proc~to_s 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 toml_load toml_load proc~load_config->toml_load

Called by

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

Source Code

subroutine options_for(cli, cache, dir, opts, stat, errmsg)
    !! The options for a file in directory `dir`: defaults, then configuration, then command line.
    type(cli_t), intent(in) :: cli                          !! the parsed command line
    type(config_cache_t), intent(inout) :: cache            !! configurations found so far
    character(len=*), intent(in) :: dir                     !! the file's directory, relative or absolute
    type(format_options_t), intent(out) :: opts             !! the options
    integer, intent(out) :: stat                            !! nonzero for an unreadable configuration or a bad setting
    character(len=:), allocatable, intent(out) :: errmsg    !! what is wrong, if `stat` is nonzero
    type(config_t) :: cfg
    integer :: k

    call config_for(cli, cache, absolute_path(dir), cfg, stat, errmsg)
    if (stat /= 0) return
    do k = 1, size(cfg%settings)
        call apply_setting(opts, cfg%settings(k)%key, cfg%settings(k)%value, stat, errmsg)
        if (stat /= 0) then
            errmsg = cfg%path//': '//errmsg
            return
        end if
    end do
    do k = 1, size(cli%settings)
        call apply_setting(opts, cli%settings(k)%key, cli%settings(k)%value, stat, errmsg)
        if (stat /= 0) return
    end do
end subroutine options_for