refactor: improve arg parsing

This commit is contained in:
Michael Vines
2019-02-15 19:59:42 -08:00
parent 18b87f4fb9
commit 6bdfce04d1

View File

@ -25,7 +25,7 @@ usage: $0 [update|up|down|logs|deploy] [command-specific options]
Operate a local testnet Operate a local testnet
update - Update the network image from dockerhub.com update - Update the image from dockerhub.com
up - Start the network up - Start the network
down - Stop the network down - Stop the network
logs - Display network logging logs - Display network logging
@ -35,9 +35,13 @@ Operate a local testnet
logs-specific options: logs-specific options:
-f - Follow log output -f - Follow log output
update/up-specific options: update-specific options:
edge - Update/start the "edge" channel network edge - Update the "edge" channel image
beta - Update/start the "beta" channel network beta - Update the "beta" channel imae
up-specific options:
edge - Start the "edge" channel image
beta - Start the "beta" channel image
-n - Optional Docker network to join -n - Optional Docker network to join
Default channel: $channel Default channel: $channel
@ -72,31 +76,39 @@ update)
) )
;; ;;
up) up)
if [[ -n $1 ]]; then while [[ -n $1 ]]; do
channel="$1" if [[ $1 = -n ]]; then
fi [[ -n $2 ]] || usage "Invalid $1 argument"
[[ $channel = edge || $channel = beta ]] || usage "Invalid channel: $channel" network="$2"
shift 2
if [[ $2 = -n ]]; then elif [[ $1 = edge ]]; then
[[ -n $3 ]] || usage "Invalid -n argument" channel=edge
network="$3" shift 1
elif [[ $1 = beta ]]; then
channel=beta
shift 1
else
usage "Unknown argument: $1"
fi fi
done
( (
set -x set -x
RUST_LOG=${RUST_LOG:-solana=warn,solana_bpf=info,solana_jsonrpc=info,solana::rpc=info,solana_fullnode=info,solana::drone=info,solana::bank=info,solana::banking_stage=info,solana::system_program=info} RUST_LOG=${RUST_LOG:-solana=warn,solana_bpf=info,solana_jsonrpc=info,solana::rpc=info,solana_fullnode=info,solana::drone=info,solana::bank=info,solana::banking_stage=info,solana::system_program=info}
docker run \ ARGS=(
--detach \ --detach
--name solana-localnet \ --name solana-localnet
--network "$network" \ --network "$network"
--rm \ --rm
--publish 8899:8899 \ --publish 8899:8899
--publish 8900:8900 \ --publish 8900:8900
--publish 9900:9900 \ --publish 9900:9900
--tty \ --tty
--env RUST_LOG="$RUST_LOG" \ --env "RUST_LOG=$RUST_LOG"
solanalabs/solana:"$channel" )
docker run "${ARGS[@]}" solanalabs/solana:"$channel"
for _ in 1 2 3 4 5; do for _ in 1 2 3 4 5; do
if curl \ if curl \