Skip to content

Commit

Permalink
chore: move command line parsing logic to main file scope
Browse files Browse the repository at this point in the history
  • Loading branch information
benpreiser committed Oct 22, 2022
1 parent 0805e17 commit de6ba9d
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions scripts/build-durable-nonce.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ const { binary_to_base58, base58_to_binary } = require('base58-js');
const { createInterface } = require('readline');
const { program, Option } = require('commander');

program
.command('create')
.description('create a new solana keypair')
.showHelpAfterError()
.action(handleCreate);

program
.command('import')
.description('import an existing solana keypair')
.showHelpAfterError()
.addOption(
new Option(
'-n, --network <solana-network>',
'network for nonce account creation'
)
.choices(['devnet', 'mainnet-beta'])
.makeOptionMandatory()
)
.action(handleImport);

const readline = createInterface({
input: process.stdin,
output: process.stdout,
Expand Down Expand Up @@ -83,30 +103,7 @@ function handleCreate() {
);
}

function defineCommands() {
program
.command('create')
.description('create a new solana keypair')
.showHelpAfterError()
.action(handleCreate);

program
.command('import')
.description('import an existing solana keypair')
.showHelpAfterError()
.addOption(
new Option(
'-n, --network <solana-network>',
'network for nonce account creation'
)
.choices(['devnet', 'mainnet-beta'])
.makeOptionMandatory()
)
.action(handleImport);
}

async function main() {
defineCommands();
await program.parseAsync(process.argv);
process.exit(0);
}
Expand Down

0 comments on commit de6ba9d

Please sign in to comment.