Skip to content

Commit

Permalink
chore: refactor cli
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Jul 17, 2024
1 parent a874436 commit b7c137a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
9 changes: 9 additions & 0 deletions sui/cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ const addExtendedOptions = (program, options = {}) => {
return program;
};

const addBaseOptionsToCommands = (program, options = {}) => {
if (program.commands.length > 0) {
program.commands.forEach((command) => {
addBaseOptions(command, options);
});
}
};

module.exports = {
addBaseOptions,
addExtendedOptions,
addBaseOptionsToCommands,
};
23 changes: 10 additions & 13 deletions sui/gas-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
utils: { arrayify },
} = ethers;

const { addBaseOptions } = require('./cli-utils');
const { addBaseOptionsToCommands } = require('./cli-utils');
const { getWallet, printWalletInfo, broadcast } = require('./sign-utils');

async function payGas(config, chain, args, options) {
Expand Down Expand Up @@ -202,7 +202,7 @@ if (require.main === module) {

program.name('gas-service').description('Interact with the gas service contract.');

const payGasProgram = new Command()
const payGasCmd = new Command()
.command('pay_gas <amount> <destination_chain> <destination_address> <payload>')
.description('Pay gas for the new contract call.')
.requiredOption('--channel <channel>', 'Existing channel ID to initiate a cross-chain message over')
Expand All @@ -212,7 +212,7 @@ if (require.main === module) {
mainProcessor('pay_gas', options, [amount, destinationChain, destinationAddress, payload], processCommand);
});

const addGasProgram = new Command()
const addGasCmd = new Command()
.command('add_gas <message_id> <amount>')
.description('Add gas for the existing contract call.')
.option('--refund_address <refundAddress>', 'Refund address.')
Expand All @@ -221,31 +221,28 @@ if (require.main === module) {
mainProcessor('add_gas', options, [messageId, amount], processCommand);
});

const collectGasProgram = new Command()
const collectGasCmd = new Command()
.command('collect_gas <amount>')
.description('Collect gas from the gas service contract.')
.option('--receiver <receiver>', 'Receiver address. Default is the sender address.')
.action((amount, options) => {
mainProcessor('collect_gas', options, [amount], processCommand);
});

const refundProgram = new Command()
const refundCmd = new Command()
.command('refund <messageId> <amount>')
.description('Refund gas from the gas service contract.')
.option('--receiver <receiver>', 'Receiver address. Default is the sender address.')
.action((messageId, amount, options) => {
mainProcessor('refund', options, [messageId, amount], processCommand);
});

program.addCommand(payGasProgram);
program.addCommand(addGasProgram);
program.addCommand(collectGasProgram);
program.addCommand(refundProgram);
program.addCommand(payGasCmd);
program.addCommand(addGasCmd);
program.addCommand(collectGasCmd);
program.addCommand(refundCmd);

addBaseOptions(payGasProgram);
addBaseOptions(addGasProgram);
addBaseOptions(collectGasProgram);
addBaseOptions(refundProgram);
addBaseOptionsToCommands(program);

program.parse();
}

0 comments on commit b7c137a

Please sign in to comment.