From 604747fd833e2cba8451bed6ee5a1569fb31e6db Mon Sep 17 00:00:00 2001 From: adnpark Date: Fri, 1 Mar 2024 23:03:57 +0900 Subject: [PATCH] refactor: make sure to select chains mutual exclusively --- src/command/index.ts | 2 +- src/utils/validate.ts | 38 +++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/command/index.ts b/src/command/index.ts index a0e7d79..e285a64 100644 --- a/src/command/index.ts +++ b/src/command/index.ts @@ -124,7 +124,7 @@ program "-s, --salt ", "salt to be used for CREATE2. This can be a full 32-byte hex string or a shorter numeric representation that will be converted to a 32-byte hex string." ) - .option("-t, --testnet-all", "select all testnets", true) + .option("-t, --testnet-all", "select all testnets", false) .option("-m, --mainnet-all", "select all mainnets", false) .option("-a, --all-networks", "select all networks", false) .option( diff --git a/src/utils/validate.ts b/src/utils/validate.ts index 3ec1941..23088b8 100644 --- a/src/utils/validate.ts +++ b/src/utils/validate.ts @@ -76,26 +76,26 @@ export const processAndValidateChains = ( options: CommandOptions ): Chain[] => { const supportedChains = getSupportedChains() - if ( - chainOption !== undefined && - (options.testnetAll || options.mainnetAll || options.allNetworks) - ) { - console.error("Error: Cannot use -c option with -t, -m, -a options") - process.exit(1) - } - - if (options.testnetAll && options.mainnetAll) { - console.error("Error: Cannot use -t and -m options together") - process.exit(1) - } - - if (options.testnetAll && options.allNetworks) { - console.error("Error: Cannot use -t and -a options together") + // Check for mutually exclusive options + const exclusiveOptions = [ + chainOption !== undefined, + options.testnetAll, + options.mainnetAll, + options.allNetworks + ] + const selectedOptionsCount = exclusiveOptions.filter( + (isSelected) => isSelected + ).length + + if (selectedOptionsCount === 0) { + console.error( + "Error: At least one of -c, -t, -m, -a options must be specified" + ) process.exit(1) - } - - if (options.mainnetAll && options.allNetworks) { - console.error("Error: Cannot use -m and -a options together") + } else if (selectedOptionsCount > 1) { + console.error( + "Error: Options -c, -t, -m, -a are mutually exclusive and cannot be used together" + ) process.exit(1) }