Apply a single --watch-* flag to the watcher options.
Supports both --flag=value and --flag value styles for flags that take
a value.
This routine is called while scanning the argv prefix before the fpm
subcommand token.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | a | |||
| integer, | intent(inout) | :: | i | |||
| integer, | intent(in) | :: | narg | |||
| type(watch_opts_t), | intent(inout) | :: | w |
subroutine apply_watch_flag(a, i, narg, w) character(len=*), intent(in) :: a integer, intent(inout) :: i integer, intent(in) :: narg type(watch_opts_t), intent(inout) :: w character(len=:), allocatable :: key, val integer :: eq key = trim(a) val = "" eq = index(key, "=") if (eq > 0) then val = key(eq+1:) key = key(1:eq-1) end if select case (key) case ("--watch-child") continue case ("--watch-auto-restart") continue case ("--watch-restart-delay") if (len_trim(val) == 0) then if (i+1 <= narg) i = i + 1 end if case ("--watch-restart-max") if (len_trim(val) == 0) then if (i+1 <= narg) i = i + 1 end if case ("--watch-self") if (len_trim(val) == 0) then if (i+1 <= narg) i = i + 1 end if case ("--watch-deps") if (len_trim(val) > 0) then w%watch_deps = parse_bool(val, .true.) else w%watch_deps = .true. end if case ("--watch-no-deps") w%watch_deps = .false. case ("--watch-low-cpu") if (len_trim(val) > 0) then w%low_cpu = parse_bool(val, .true.) else w%low_cpu = .true. end if case ("--watch-no-low-cpu") w%low_cpu = .false. case ("--watch-quiet") w%verbosity = -1 case ("--watch-verbose") if (len_trim(val) > 0) then w%verbosity = max(w%verbosity, parse_int(val, 1)) else w%verbosity = max(w%verbosity, 1) end if case ("--watch-very-verbose") w%verbosity = max(w%verbosity, 2) case ("--watch-debug") w%debug = .true. case ("--watch-print-files") w%print_files_once = .true. w%verbosity = max(w%verbosity, 2) case ("--watch-silent-fpm") w%silent_fpm = .true. case ("--watch-run-on-start") w%run_on_start = .true. case ("--watch-no-run-on-start") w%run_on_start = .false. case ("--watch-rescan") if (len_trim(val) == 0) then if (i+1 > narg) call usage_and_stop("--watch-rescan requires a value") val = get_arg(i+1) i = i + 1 end if w%rescan = parse_real(val, w%rescan) case ("--watch-no-rescan") w%rescan = 0.0 case ("--watch-ignore") if (len_trim(val) == 0) then if (i+1 > narg) call usage_and_stop("--watch-ignore requires a value") val = get_arg(i+1) i = i + 1 end if call push_feature(w%ignore, trim(val)) case ("--watch-include") if (len_trim(val) == 0) then if (i+1 > narg) call usage_and_stop("--watch-include requires a value") val = get_arg(i+1) i = i + 1 end if call push_feature(w%include, trim(val)) case ("--watch-feature") if (len_trim(val) == 0) then if (i+1 > narg) call usage_and_stop("--watch-feature requires a value") val = get_arg(i+1) i = i + 1 end if call push_feature(w%enabled_features, trim(val)) case ("--watch-poll") if (len_trim(val) == 0) then if (i+1 > narg) call usage_and_stop("--watch-poll requires a value") val = get_arg(i+1) i = i + 1 end if w%poll = parse_real(val, w%poll) case ("--watch-debounce") if (len_trim(val) == 0) then if (i+1 > narg) call usage_and_stop("--watch-debounce requires a value") val = get_arg(i+1) i = i + 1 end if w%debounce = parse_real(val, w%debounce) case ("--watch-once") if (len_trim(val) > 0) then w%once = parse_bool(val, .true.) else w%once = .true. end if case ("--watch-help") call usage_and_stop_ok() case default call usage_and_stop("unknown watch flag: " // trim(a)) end select call normalize_watch_opts(w) contains pure logical function parse_bool(s, default) result(v) character(len=*), intent(in) :: s logical, intent(in) :: default character(len=:), allocatable :: t t = trim(adjustl(lower_ascii(s))) select case (t) case ("1","true","on","yes","y","t") v = .true. case ("0","false","off","no","n","f") v = .false. case default v = default end select end function parse_bool pure function lower_ascii(s) result(r) character(len=*), intent(in) :: s character(len=len(s)) :: r integer :: k, c, da da = iachar('a') - iachar('A') do k = 1, len(s) c = iachar(s(k:k)) if (c >= iachar('A') .and. c <= iachar('Z')) then r(k:k) = achar(c + da) else r(k:k) = s(k:k) end if end do end function lower_ascii end subroutine apply_watch_flag