A peer-to-peer stack for code collaboration
#!/usr/bin/env bash
usage() {
cat <<USAGEDOC
USAGE
$0 <machine> <cmd>
Initialize and interact with a simple counter machine.
<machine> init
Initializes the machine with a prelude that defines the counter semantics.
<machine> get-value
Prints the current value of the counter.
<machine> increment
Increments the value of the counter by one and prints it.
EXAMPLE
> $0 my-machine-id init
> $0 my-machine-id get-value
0
> $0 my-machine-id increment
1
> $0 my-machine-id get-value
1
USAGEDOC
exit 1
}
machine=
cmd=
while [[ $# -gt 0 ]]; do
case "$1" in
-h | --help ) usage;;
* )
if [[ -z "$machine" ]]; then
machine=$1
elif [[ -z "$cmd" ]]; then
cmd=$1
else
echo "Too many arguments"
exit 1
fi;;
esac
shift
done
if [[ -z "$machine" ]]; then
echo "Argument <machine> is missing"
exit 1
elif [[ -z "$cmd" ]]; then
echo "Argument <cmd> is missing"
exit 1
fi
case "$cmd" in
init )
radicle - <<-SCRIPT
(load! (find-module-file! "examples/counter.rad"))
(counter/init-machine! "${machine}")
SCRIPT
;;
get-value )
radicle - <<-SCRIPT
(load! (find-module-file! "examples/counter.rad"))
(counter/get-value "${machine}")
SCRIPT
;;
increment )
radicle - <<-SCRIPT
(load! (find-module-file! "examples/counter.rad"))
(counter/increment! "${machine}")
SCRIPT
;;
* )
echo "Unknown command: $cmd"
exit 1
;;
esac