run_command_and_report Subroutine

public subroutine run_command_and_report(cmd, w, exitstat, secs)

Execute a command and print pre/post status lines.

This routine is responsible for: - Printing a "run" line (unless quiet), - Executing the command via fpm_filesystem:run, - Timing the execution with system_clock, - Printing a final OK/FAIL summary and returning exitstat and secs.

When w%silent_fpm is true, the executed command's output is suppressed (but the status lines from fpm-watch remain visible).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: cmd
type(watch_opts_t), intent(in) :: w
integer, intent(out) :: exitstat
real, intent(out) :: secs

Calls

proc~~run_command_and_report~~CallsGraph proc~run_command_and_report run_command_and_report colorize colorize proc~run_command_and_report->colorize proc~ftoa ftoa proc~run_command_and_report->proc~ftoa run run proc~run_command_and_report->run str str proc~run_command_and_report->str

Called by

proc~~run_command_and_report~~CalledByGraph proc~run_command_and_report run_command_and_report proc~run_once run_once proc~run_once->proc~run_command_and_report proc~watcher_run watcher_t%watcher_run proc~watcher_run->proc~run_command_and_report proc~watcher_init watcher_t%watcher_init proc~watcher_init->proc~run_once

Source Code

   subroutine run_command_and_report(cmd, w, exitstat, secs)
      character(len=*), intent(in) :: cmd
      type(watch_opts_t), intent(in) :: w
      integer, intent(out) :: exitstat
      real, intent(out) :: secs

      integer(int64) :: rate, t0, t1
      logical :: verbose_run
      character(len=:), allocatable :: status_color
      character(len=:), allocatable :: status_word

      call system_clock(count_rate=rate)
      if (rate <= 0_int64) rate = 1000_int64

      verbose_run = .not. w%silent_fpm

      if (w%verbosity >= 0) then
         if (w%silent_fpm) then
            write(output_unit,'(a)') &
               colorize("run        |", color_fg='cyan_intense', style='bold_on') // "  " // &
               colorize(trim(cmd), color_fg='white_intense') // "  " // &
               colorize("(fpm output silenced)", color_fg='magenta_intense', style='italics_on')
         else
            write(output_unit,'(a)') &
               colorize("run        |", color_fg='cyan_intense', style='bold_on') // "  " // &
               colorize(trim(cmd), color_fg='white_intense')
         end if
      end if

      if (w%verbosity >= 0) flush(output_unit)

      call system_clock(t0)
      call run(trim(cmd), echo=.false., exitstat=exitstat, verbose=verbose_run)
      call system_clock(t1)

      secs = real(t1 - t0) / real(rate)

      if (exitstat == 0) then
         status_color = "green_intense"
         status_word  = "OK"
      else
         status_color = "red_intense"
         status_word  = "FAIL"
      end if

      if (w%verbosity >= 0) then
         write(output_unit,'(a)') ""
         write(output_unit,'(a)') &
            colorize("done       |", color_fg=status_color, style='bold_on') // &
            "  " // colorize(status_word, color_fg=status_color, style='bold_on') // &
            "  exit=" // colorize(str(exitstat), color_fg=status_color, style='bold_on') // &
            "  time=" // colorize(ftoa(secs), color_fg='yellow_intense') // "s"

         write(output_unit,'(a)') &
            colorize("command    |", color_fg='cyan_intense', style='bold_on') // "  " // &
            colorize(trim(cmd), color_fg='white_intense')

         write(output_unit,'(a)') &
            colorize("watch      |", color_fg='cyan_intense', style='bold_on') // &
            "  waiting (poll=" // colorize(ftoa(w%poll), color_fg='yellow') // "s" // &
            ", debounce=" // colorize(ftoa(w%debounce), color_fg='yellow') // "s)  " // &
            colorize("Ctrl+C", color_fg='red_intense', style='bold_on') // " to stop"
      end if
   end subroutine run_command_and_report