Skip to content

Commit c622649

Browse files
implementing helper
1 parent 03230cb commit c622649

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

scripts/ops/dev-cluster/dev-menu.sh

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,33 @@ source "${SCRIPT_DIR}/../common.sh"
1818
# shellcheck source=dev-common.sh
1919
source "${SCRIPT_DIR}/dev-common.sh"
2020

21-
# Validated here so a typo re-prompts instead of hitting die().
22-
ask_network() {
23-
local choice
21+
# Sets NETWORK: a valid CLI argument passes, an invalid one dies (so scripted
22+
# use fails loudly), no argument prompts until valid.
23+
resolve_network() {
24+
NETWORK="${1:-}"
25+
[[ -z "$NETWORK" ]] || case "$NETWORK" in
26+
testnet|mainnet) return 0 ;;
27+
*) die "Unknown network '${NETWORK}' (expected testnet|mainnet)." ;;
28+
esac
2429
while true; do
25-
read -rp "Network (testnet|mainnet) [testnet]: " choice
26-
NETWORK="${choice:-testnet}"
30+
read -rp "Network (testnet|mainnet) [testnet]: " NETWORK
31+
NETWORK="${NETWORK:-testnet}"
2732
case "$NETWORK" in
2833
testnet|mainnet) return 0 ;;
2934
*) echo "Unknown network '${NETWORK}'." ;;
3035
esac
3136
done
3237
}
3338

34-
NETWORK="${1:-}"
35-
VERSION="${2:-}"
36-
case "$NETWORK" in
37-
testnet|mainnet) ;;
38-
"") ask_network ;;
39-
*) die "Unknown network '${NETWORK}' (expected testnet|mainnet)." ;;
40-
esac
41-
if [[ -z "$VERSION" ]]; then
42-
read -rp "Version (e.g. 3.14.0): " VERSION
43-
fi
44-
check_version "$VERSION"
39+
# Sets VERSION from the CLI argument or a prompt, then validates it.
40+
resolve_version() {
41+
VERSION="${1:-}"
42+
[[ -n "$VERSION" ]] || read -rp "Version (e.g. 3.14.0): " VERSION
43+
check_version "$VERSION"
44+
}
45+
46+
resolve_network "${1:-}"
47+
resolve_version "${2:-}"
4548

4649
resolve_dev_cluster "$NETWORK"
4750
prompt_nomad_ip "$NETWORK"

0 commit comments

Comments
 (0)