fdoc

functionrun

integer function run(args) result(status)

Run with command line args, returning the exit status.

Arguments

NameTypeIntentAttributesDescription
argstype(string_t)indimension(:)

the arguments, in order

Result

NameTypeAttributesDescription
statusinteger

Calls

Source

Show the code
integer function run(args) result(status)
    type(string_t), intent(in) :: args(:)   !! the arguments, in order
    type(args_t) :: parsed
    type(settings_t), target :: s
    type(project_t), target :: p
    type(markdown_options_t) :: options, front_options
    type(page_t), allocatable :: static(:)
    character(len=:), allocatable :: errmsg, body, directory, front
    character(len=16) :: count_text
    integer :: stat, pages

    status = 0
    call parse_args(args, parsed, stat, errmsg)
    if (stat /= 0) then
        write (error_unit, '(a)') 'fdoc: '//errmsg
        write (error_unit, '(a)') 'Try "fdoc --help".'
        status = 2
        return
    end if
    if (parsed%action == ACTION_HELP) then
        write (output_unit, '(a)', advance='no') usage()
        return
    end if
    if (parsed%action == ACTION_VERSION) then
        write (output_unit, '(a)') 'fdoc version '//VERSION
        return
    end if

    if (parsed%action == ACTION_MARKDOWN) then
        call markdown_list(parsed%project_file)
        return
    end if

    directory = '.'
    if (len(parsed%project_file) > 0) directory = parent_directory(parsed%project_file)
    call load_project(parsed%project_file, directory, s, body, stat, errmsg)
    ! all of the settings first, as the checks also work out what follows from them
    if (stat == 0 .and. allocated(parsed%config)) call apply_toml_string(parsed%config, s, stat, errmsg)
    if (stat == 0) call apply_args(parsed, s, stat, errmsg)
    if (stat == 0) call check_settings(s, stat, errmsg)
    if (stat == 0) call finish_settings(s, directory, stat, errmsg)
    if (stat /= 0) then
        write (error_unit, '(a)') 'fdoc: '//errmsg
        status = 1
        return
    end if

    if (parsed%action == ACTION_DUMP) then
        write (output_unit, '(a)', advance='no') dump_settings(s)
        return
    end if

    if (parsed%action /= ACTION_DUMP_LINKS .and. (parsed%progress_lines .or. .not. s%quiet)) then
        call progress_enable(parsed%progress_lines)
    end if
    call warn_unsupported(s)
    call load_project_sources(s, p, stat, errmsg)
    if (stat /= 0) then
        write (error_unit, '(a)') 'fdoc: '//errmsg
        status = 1
        return
    end if
    call progress_start('Connecting entities', p%list%n)
    call correlate(p, s)
    call link_project(p)
    call prune(p, s)
    call progress_finish()
    if (parsed%action == ACTION_DUMP_LINKS) then
        call write_text(dump_links(p))
        return
    end if
    call assign_pages(p)
    call base_options(s, '..', options)
    call collect_abbreviations(p, options)
    call index_entity_names(p%list)
    call render_documentation(p, s, options)
    call base_options(s, '.', front_options)
    if (allocated(options%abbreviations)) front_options%abbreviations = options%abbreviations
    call render_text(p, front_options, 0, '', body, front)
    call load_pages(p, s, options, static)
    call write_site(p, s, front, static, pages, stat, errmsg)
    if (stat == 0 .and. s%externalize) call write_modules(p, s, stat, errmsg)
    if (stat /= 0) then
        write (error_unit, '(a)') 'fdoc: '//errmsg
        status = 1
        return
    end if
    write (count_text, '(i0)') pages
    call progress_summary(trim(count_text)//' pages written to '//s%output_dir)
end function run