Skip to content

Commit

Permalink
feat: add option to iterate over chain's type
Browse files Browse the repository at this point in the history
  • Loading branch information
blockchainguyy committed Sep 24, 2024
1 parent b34985a commit d3ff44d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 2 additions & 3 deletions common/cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ const addBaseOptions = (program, options = {}) => {
program.addOption(new Option('--gasOptions <gasOptions>', 'gas options cli override'));

if (!options.ignoreChainNames) {
program.addOption(
new Option('-n, --chainNames <chainNames>', 'chains to run the script over').makeOptionMandatory(true).env('CHAINS'),
);
program.addOption(new Option('-n, --chainNames <chainNames>', 'chains to run the script over').env('CHAINS'));
program.addOption(new Option('--skipChains <skipChains>', 'chains to skip over'));
program.addOption(
new Option(
'--startFromChain <startFromChain>',
'start from a specific chain onwards in the config, useful when a cmd fails for an intermediate chain',
),
);
program.addOption(new Option('--chainType <chainType>', 'chain type to run script over'));
}

if (!options.ignorePrivateKey) {
Expand Down
19 changes: 14 additions & 5 deletions evm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,18 +636,27 @@ const mainProcessor = async (options, processCommand, save = true, catchErr = fa
throw new Error('Environment was not provided');
}

if (!options.chainName && !options.chainNames) {
throw new Error('Chain names were not provided');
}

printInfo('Environment', options.env);

const config = loadConfig(options.env);
let chains = options.chainName ? [options.chainName] : options.chainNames.split(',');
const chainsToSkip = (options.skipChains || '').split(',').map((str) => str.trim().toLowerCase());

let chains = [];

if (options.chainNames === 'all') {
chains = Object.keys(config.chains);
chains = chains.map((chain) => chain.trim().toLowerCase());
} else if (options.chainType) {
chains = Object.keys(config.chains);
chains.filter((chain) => config.chains[chain].chainType === options.chainType);
} else if (options.chainName) {
chains = [options.chainName];
} else if (options.chainNames) {
chains = options.chainNames.split(',');
}

if (chains.length === 0) {
throw new Error('Chain names were not provided');
}

chains = chains.map((chain) => chain.trim().toLowerCase());
Expand Down

0 comments on commit d3ff44d

Please sign in to comment.