'use strict' ; import { UserInputUtil , IBlockchainQuickPickItem } from './UserInputUtil' ; import { VSCodeBlockchainOutputAdapter } from '../logging/VSCodeBlockchainOutputAdapter' ; import { GatewayTreeItem } from '../explorer/model/GatewayTreeItem' ; import { LogType , FabricGatewayRegistry , FabricGatewayRegistryEntry } from 'ibm-blockchain-platform-common' ; export async function deleteGateway ( gatewayTreeItem ) { const outputAdapter = VSCodeBlockchainOutputAdapter . instance ( ) ; outputAdapter . log ( LogType . INFO , undefined , `deleteGateway` ) ; let gatewaysToDelete ; if ( ! gatewayTreeItem ) { let gateways = [ ] ; gateways = await FabricGatewayRegistry . instance ( ) . getAll ( false ) ; if ( gateways . length === 0 ) { outputAdapter . log ( LogType . ERROR , `No gateways to delete. Local gateways cannot be deleted.` ) ; return ; } const chosenGateway = await UserInputUtil . showGatewayQuickPickBox ( 'Choose the gateway(s) that you want to delete' , true , false ) as IBlockchainQuickPickItem < FabricGatewayRegistryEntry > [ ] ; if ( ! chosenGateway || chosenGateway . length === 0 ) { return ; } gatewaysToDelete = chosenGateway . map ( ( _gateway ) => { return _gateway . data ; } ) ; } else { gatewaysToDelete = [ gatewayTreeItem . gateway ] ; } const reallyDoIt = await UserInputUtil . showConfirmationWarningMessage ( `This will remove the gateway(s). Do you want to continue?` ) ; if ( ! reallyDoIt ) { return ; } for ( const _gateway of gatewaysToDelete ) { await FabricGatewayRegistry . instance ( ) . delete ( _gateway . name ) ; } if ( gatewaysToDelete . length > 1 ) { outputAdapter . log ( LogType . SUCCESS , `Successfully deleted gateways` ) ; return ; } else { outputAdapter . log ( LogType . SUCCESS , `Successfully deleted ${ gatewaysToDelete [ 0 ] . name } gateway` ) ; return ; } }