#!/bin/sh
self=`basename $0`
[ -z "$1" -o "$1" = '--help' ] && { cat <<END >&2
Background espclient command -- 8/24/22 brent@mbari.org
Usage:
  $self clientArgs -- clientRubyCmd
clientArgs are passed through to espclient and onESP
clientRubyCmd is piped into espclient
==> Any arguments containing punctuation '<>\`#*&()~$' must be 'quoted' <==

Examples:
  $self myName -- slot spare:3   #set the number of spare cartridges to 3
  $self myName -- 'slot [24..19,16]=>:dry'   #mark slots 24..19 and 16 as dry
  $self myName -- 'ESP.ready!; BACsampler.prime; Cmd.stop'  #prime lines
  $self --stayOn myName -- 'ESP.ready!'   #power up and stay on
  $self --offAfter myName -- Cmd.stop     #lock carousel and shutdown
END
    exit 2
}
unset clientArgs onESPargs
while [ "$1" ]; do
  case "$1" in
    --)
      shift; break
  ;;
    --offAfter|--offNow|--stayOn)
      onESPargs="$onESPargs $1"
  ;;
    *)
      clientArgs="$clientArgs $1"
  esac
  shift
done
: ${name:=$self}
export name
start sh -c "echo '$@' | onESP $onESPargs espclient $clientArgs"
