route_command Subroutine

public subroutine route_command(exit_code)

Arguments

Type IntentOptional Attributes Name
integer, intent(out) :: exit_code

Source Code

    subroutine route_command(exit_code)
        integer, intent(out) :: exit_code

        integer :: nargs, i
        character(len=256) :: arg
        character(len=256), allocatable :: test_args(:)
        integer :: test_argc
        logical :: test_mode

        exit_code = 0
        test_mode = .false.

        ! Check command line arguments for --test
        nargs = command_argument_count()

        if (nargs > 0) then
            call get_command_argument(1, arg)
            if (trim(arg) == '--test') then
                test_mode = .true.

                ! Collect remaining arguments for test command
                test_argc = nargs - 1
                if (test_argc > 0) then
                    allocate (test_args(test_argc))
                    do i = 1, test_argc
                        call get_command_argument(i + 1, test_args(i))
                    end do
                    call handle_test_command(test_args, exit_code)
                    deallocate (test_args)
                else
                    ! No additional arguments, just run all tests
                    allocate (test_args(0))
                    call handle_test_command(test_args, exit_code)
                    deallocate (test_args)
                end if
                return
            end if
        end if

        ! Not test mode, delegate to original main logic
        call run_original_main(exit_code)
    end subroutine route_command