Skip to content

Commit

Permalink
sui: add script for switching Move.toml files between networks
Browse files Browse the repository at this point in the history
  • Loading branch information
kcsongor authored and evan-gray committed Apr 12, 2024
1 parent 5c83646 commit 30eacd9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions sui/scripts/switch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

network="$1"
valid_networks=("devnet" "testnet" "mainnet" "reset")

usage() {
echo "Usage: $0 {devnet|testnet|mainnet|reset}" >&2
exit 1
}

if [[ ! " ${valid_networks[@]} " =~ " ${network} " ]]; then
echo "Error: Unrecognized network '${network}'."
usage
fi

git ls-files | grep 'Move.toml' | while read -r file; do
if [[ "$network" == "reset" ]]; then
echo "Resetting $file"
git checkout "$file" --quiet
else
dir=$(dirname "$file")
base=$(basename "$file")
new_file="${dir}/Move.$network.toml"
if [ -f "$new_file" ]; then
echo "Switching $file to $new_file"
rm "$file"
# Create a relative symlink
(cd "$dir" && ln -s "$(basename "$new_file")" "$base")
fi
fi
done

0 comments on commit 30eacd9

Please sign in to comment.