Skip to content

Commit

Permalink
refactor: make sure to select chains mutual exclusively
Browse files Browse the repository at this point in the history
  • Loading branch information
adnpark committed Mar 1, 2024
1 parent 1df6dad commit 604747f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ program
"-s, --salt <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(
Expand Down
38 changes: 19 additions & 19 deletions src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 604747f

Please sign in to comment.