#!/command/execlineb

#
# with-retries -n numretries -t millisecs prog...
#

elgetopt "n:t:"
multisubstitute
{
  importas -u -D 3 nretries ELGETOPT_n
  importas -u -D 500 timeout ELGETOPT_t
  elgetpositionals -P0
}
emptyenv -oP
forbacktickx -x 0,1 -d"\n" i { s6-seq 0 ${nretries} }
  importas -u i i
  if { eltest ${i} -ne ${nretries} }
  foreground
  {
    s6-maximumtime -t ${timeout}
    $@
  }
  importas -u ? ?
  if -x 99 { eltest ${?} -eq 0 }
