Skip to content

Commit

Permalink
Add simple REPL shell script (#1427)
Browse files Browse the repository at this point in the history
* add script to work as a minimal REPL, that can be run from different window or machine
  • Loading branch information
xsebek authored Aug 11, 2024
1 parent c3b7a5d commit 9af6508
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions scripts/remote-repl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

PORT="5357"
HOST="localhost"

function help {
echo "Swarm remote REPL"
echo
echo "This is a shortcut for sending (TBD: and recieving) to Swarm REPL via cURL:"
echo "curl --header \"Content-Type: text/plain;charset=utf-8\" --data \"build {}\" $HOST:$PORT/code/run"
echo
echo "Options:"
echo " -p PORT --port PORT Specify the port, default is $PORT."
echo " -n NAME --hostaname NAME Specify the hostaname, default is $HOST."
echo " -h --help Show this helpful text."
}

function parse_args {
while [[ $# -gt 0 ]]; do
case $1 in
-p|--port)
EXTENSION="$2"
shift # past argument
shift # past value
;;
-n|--hostname)
HOST="$2"
shift # past argument
shift # past value
;;
-h|--help)
help
exit 0
;;
*)
echo "Unknown argument $1"
shift # past argument
;;
esac
done
}

function repl {
while true; do
read -p "> " expr
curl --header "Content-Type: text/plain;charset=utf-8" --data "$expr" $HOST:$PORT/code/run
done
}

function main {
parse_args
repl
}

main

0 comments on commit 9af6508

Please sign in to comment.