Browse Source

Make a couple of parameters optional

main v0.0.1
Tony Garnock-Jones 2 months ago
parent
commit
e5f8933f26
  1. 11
      lib/syndicate.sh

11
lib/syndicate.sh

@ -41,7 +41,7 @@ ds_project() {
echo "$input" | preserves-tool convert --indent=no --select "$selector" "$@"
}
# ds_connect_stdio <code>
# ds_connect_stdio [<code>]
#
# Uses stdin for input from our peer, and stdout to send output to our
# peer, connecting them to fds 5 and 6 respectively before evalutating
@ -49,12 +49,13 @@ ds_project() {
#
ds_connect_stdio() {
exec 5<&0 6>&1
eval "$1"
exec </dev/null >&2
eval "${1:-:}"
ds_flush
ds_mainloop
}
# ds_connect <addr> <code>
# ds_connect <addr> [<code>]
#
# `addr` should match schema transportAddress.Tcp,
# transportAddress.Unix, or transportAddress.Stdio. Uses `nc` for the
@ -67,7 +68,7 @@ ds_connect() {
case $(ds_project "$addr" ".^") in
tcp) nc_args="$(ds_project "$addr" ". 0" --output-format=unquoted) $(ds_project "$addr" ". 1")";;
unix) nc_args="-U $(ds_project "$addr" ". 0" --output-format=unquoted)";;
stdio) ds_connect_stdio "$2"; return;;
stdio) ds_connect_stdio "${2:-:}"; return;;
*) echo "ds_connect: address '$addr' not supported"; return 1;;
esac
@ -76,7 +77,7 @@ ds_connect() {
trap "rm -f $f" 2 EXIT RETURN
{
eval "$2"
eval "${2:-:}"
ds_flush
ds_mainloop
} 5< <(nc $nc_args <$f) 6>$f

Loading…
Cancel
Save