diff --git a/src/cli/commands/wallet/remove.mts b/src/cli/commands/wallet/remove.mts index 1c16e57..212aecc 100644 --- a/src/cli/commands/wallet/remove.mts +++ b/src/cli/commands/wallet/remove.mts @@ -4,6 +4,7 @@ import { repositories as repos } from '../../../persistence/repository.mjs'; import { printer } from '../../output/index.mjs'; import { ensureCliLevelSecretInitialized } from '../../../env/index.mjs'; import { CliError } from '../../../error/cli-error.mjs'; +import { withErrorHandler } from '../../utils/error-handler.mjs'; export const walletRemoveCommand = new Command() .name('remove') @@ -12,29 +13,23 @@ export const walletRemoveCommand = new Command() .argument('', 'Wallet alias') .option('-y --yes', 'Skip confirmation') - .action(async (walletAlias, opts, cmd) => { - try { - await ensureCliLevelSecretInitialized() - const walletData = await repos.wallet.getWallet(walletAlias) - if (walletData === undefined) { - printer.error(`Wallet with alias '${walletAlias}' not found`); - return; - } - - if (!opts.yes) { - const answer = await prompts({ - type: 'confirm', - name: 'value', - message: `Are you sure you want to remove wallet '${walletAlias}' [${walletData.accounts.map(a => a.alias).join(', ')}]?` - }); - if (!answer.value) return; - } + .action(withErrorHandler(async (walletAlias, opts, cmd) => { + await ensureCliLevelSecretInitialized() + const walletData = await repos.wallet.getWallet(walletAlias) + if (walletData === undefined) { + printer.error(`Wallet with alias '${walletAlias}' not found`); + return; + } - await repos.wallet.remove(walletAlias); - printer.info(`Wallet '${walletAlias}' removed`); - } catch (e: unknown) { - if (e instanceof CliError) { - printer.error(e.message) - } + if (!opts.yes) { + const answer = await prompts({ + type: 'confirm', + name: 'value', + message: `Are you sure you want to remove wallet '${walletAlias}' [${walletData.accounts.map(a => a.alias).join(', ')}]?` + }); + if (!answer.value) return; } - }) + + await repos.wallet.remove(walletAlias); + printer.info(`Wallet '${walletAlias}' removed`); + }))