From 54fcdc4a3c2cfed79b84da963d7bfa8514e98794 Mon Sep 17 00:00:00 2001 From: npty <78221556+npty@users.noreply.github.com> Date: Thu, 22 Aug 2024 19:32:47 +0700 Subject: [PATCH] chore: reuse addEnvOptions (#344) --- common/cli-utils.js | 19 ++++++++++++++++--- cosmwasm/cli-utils.js | 4 ++-- cosmwasm/deploy-contract.js | 5 +++++ cosmwasm/submit-proposal.js | 18 ++++++++++++++++++ stellar/balances.js | 9 ++------- stellar/deploy-contract.js | 9 ++------- stellar/generate-bindings.js | 9 ++------- stellar/operators.js | 10 ++-------- sui/utils/cli-utils.js | 9 ++------- 9 files changed, 51 insertions(+), 41 deletions(-) diff --git a/common/cli-utils.js b/common/cli-utils.js index 1bcb7173..189aee26 100644 --- a/common/cli-utils.js +++ b/common/cli-utils.js @@ -2,16 +2,28 @@ require('dotenv').config(); +const fs = require('fs'); const { Option } = require('commander'); -const addBaseOptions = (program, options = {}) => { +// A path to the chain configuration files +const CHAIN_CONFIG_PATH = `${__dirname}/../axelar-chains-config/info`; + +// A list of available chain environments which are the names of the files in the CHAIN_CONFIG_PATH +const CHAIN_ENVIRONMENTS = fs.readdirSync(CHAIN_CONFIG_PATH).map((chainName) => chainName.split('.')[0]); + +const addEnvOption = (program, defaultValue) => { program.addOption( new Option('-e, --env ', 'environment') - .choices(['local', 'devnet', 'devnet-amplifier', 'devnet-verifiers', 'stagenet', 'testnet', 'mainnet']) - .default('testnet') + .choices(CHAIN_ENVIRONMENTS) + .default(defaultValue || 'testnet') .makeOptionMandatory(true) .env('ENV'), ); +}; + +const addBaseOptions = (program, options = {}) => { + addEnvOption(program); + program.addOption(new Option('-y, --yes', 'skip deployment prompt confirmation').env('YES')); if (!options.ignoreParallel) { @@ -93,6 +105,7 @@ const addExtendedOptions = (program, options = {}) => { }; module.exports = { + addEnvOption, addBaseOptions, addExtendedOptions, }; diff --git a/cosmwasm/cli-utils.js b/cosmwasm/cli-utils.js index e1ef6a40..684f3382 100644 --- a/cosmwasm/cli-utils.js +++ b/cosmwasm/cli-utils.js @@ -2,7 +2,7 @@ require('dotenv').config(); -const { addExtendedOptions } = require('../common'); +const { addExtendedOptions, addEnvOption } = require('../common'); const { governanceAddress } = require('./utils'); const { Option } = require('commander'); @@ -20,8 +20,8 @@ const addCommonAmplifierOptions = (program, options = {}) => { ...options, }; + addEnvOption(program); addExtendedOptions(program, ops); - program.addOption(new Option('-m, --mnemonic ', 'mnemonic').makeOptionMandatory(true).env('MNEMONIC')); program.addOption(new Option('-a, --artifactPath ', 'artifact path').makeOptionMandatory(true).env('ARTIFACT_PATH')); program.addOption(new Option('--aarch64', 'aarch64').env('AARCH64').default(false)); diff --git a/cosmwasm/deploy-contract.js b/cosmwasm/deploy-contract.js index 7b722c37..da49d2f8 100644 --- a/cosmwasm/deploy-contract.js +++ b/cosmwasm/deploy-contract.js @@ -3,6 +3,7 @@ require('dotenv').config(); const { isNil } = require('lodash'); +const { addEnvOption } = require('../common'); const { isNumber, printInfo, loadConfig, saveConfig, prompt } = require('../evm/utils'); const { prepareWallet, @@ -114,6 +115,10 @@ const programHandler = () => { addCommonAmplifierOptions(program); + program.addOption(new Option('-m, --mnemonic ', 'mnemonic').makeOptionMandatory(true).env('MNEMONIC')); + program.addOption(new Option('-a, --artifactPath ', 'artifact path').makeOptionMandatory(true).env('ARTIFACT_PATH')); + program.addOption(new Option('-c, --contractName ', 'contract name').makeOptionMandatory(true)); + program.addOption(new Option('-n, --chainNames ', 'chain names').default('none')); program.addOption(new Option('-r, --reuseCodeId', 'reuse code Id')); program.addOption( new Option( diff --git a/cosmwasm/submit-proposal.js b/cosmwasm/submit-proposal.js index c2d8059b..e56b941d 100644 --- a/cosmwasm/submit-proposal.js +++ b/cosmwasm/submit-proposal.js @@ -22,6 +22,7 @@ const { governanceAddress, } = require('./utils'); const { isNumber, saveConfig, loadConfig, printInfo, prompt } = require('../evm/utils'); +const { addEnvOption } = require('../common'); const { StoreCodeProposal, StoreAndInstantiateContractProposal, @@ -251,6 +252,23 @@ const programHandler = () => { addCommonAmplifierOptions(program, { predictOnly: true }); + // TODO: combine deploy-contract and submit-proposal options to remove duplicates + program.addOption(new Option('-m, --mnemonic ', 'mnemonic').makeOptionMandatory(true).env('MNEMONIC')); + program.addOption(new Option('-a, --artifactPath ', 'artifact path').makeOptionMandatory(true).env('ARTIFACT_PATH')); + program.addOption(new Option('-c, --contractName ', 'contract name').makeOptionMandatory(true)); + program.addOption(new Option('-n, --chainNames ', 'chain names').default('none')); + + program.addOption(new Option('-s, --salt ', 'salt for instantiate2. defaults to contract name').env('SALT')); + program.addOption( + new Option('--admin
', 'when instantiating contract, set an admin address. Defaults to governance module account').default( + governanceAddress, + ), + ); + program.addOption(new Option('--instantiate2', 'use instantiate2 for constant address deployment')); + program.addOption(new Option('-l, --label