Skip to content

Commit

Permalink
Merge pull request #707 from liquity/bool-args
Browse files Browse the repository at this point in the history
[deploy-cli] fix: not being able to override env bools
  • Loading branch information
bingen authored Jan 18, 2025
2 parents 23bced5 + f8cbe9b commit 3fdd887
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions contracts/utils/deploy-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const argv = minimist(process.argv.slice(2), {
alias: {
h: "help",
},
boolean: [
// We don't explicitly declare any options as boolean, so that we may tell the difference between an option missing
// or it being explicitly set to false
string: [
"debug",
"help",
"open-demo-troves",
Expand All @@ -69,8 +71,6 @@ const argv = minimist(process.argv.slice(2), {
"slow",
"unlocked",
"use-testnet-pricefeeds",
],
string: [
"chain-id",
"deployer",
"etherscan-api-key",
Expand Down Expand Up @@ -315,11 +315,15 @@ function safeParseInt(value: string) {
return isNaN(parsed) ? undefined : parsed;
}

function envBool(name: string): boolean {
return process.env[name] !== undefined
&& process.env[name].length > 0
&& process.env[name] !== "false"
&& process.env[name] !== "no";
function parseBool(optionValue: string | undefined, envVar: string): boolean {
const envValue = process.env[envVar];
const coalescedValue = optionValue ?? envValue;

return coalescedValue !== undefined
&& coalescedValue !== ""
&& coalescedValue !== "false"
&& coalescedValue !== "no"
&& coalescedValue !== "0";
}

async function parseArgs() {
Expand Down Expand Up @@ -347,17 +351,17 @@ async function parseArgs() {
const [networkPreset] = argv._;

options.chainId ??= safeParseInt(process.env.CHAIN_ID ?? "");
options.debug ||= envBool("DEBUG");
options.debug = parseBool(options.debug, "DEBUG");
options.deployer ??= process.env.DEPLOYER;
options.etherscanApiKey ??= process.env.ETHERSCAN_API_KEY;
options.ledgerPath ??= process.env.LEDGER_PATH;
options.mode ??= process.env.DEPLOYMENT_MODE;
options.openDemoTroves ||= envBool("OPEN_DEMO_TROVES");
options.openDemoTroves = parseBool(options.openDemoTroves, "OPEN_DEMO_TROVES");
options.rpcUrl ??= process.env.RPC_URL;
options.salt ??= process.env.SALT;
options.unlocked ||= envBool("UNLOCKED");
options.useTestnetPricefeeds ||= envBool("USE_TESTNET_PRICEFEEDS");
options.verify ||= envBool("VERIFY");
options.unlocked = parseBool(options.unlocked, "UNLOCKED");
options.useTestnetPricefeeds = parseBool(options.useTestnetPricefeeds, "USE_TESTNET_PRICEFEEDS");
options.verify = parseBool(options.verify, "VERIFY");
options.verifier ??= process.env.VERIFIER;
options.verifierUrl ??= process.env.VERIFIER_URL;

Expand Down

0 comments on commit 3fdd887

Please sign in to comment.