-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple REPL shell script (#1427)
* add script to work as a minimal REPL, that can be run from different window or machine
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |