UNPKG

@boostercloud/cli

Version:

CLI of the Booster Framework, the next level of abstraction for cloud-native applications

60 lines (59 loc) 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const base_command_1 = require("../common/base-command"); const provider_service_1 = require("../services/provider-service"); const config_service_1 = require("../services/config-service"); const script_1 = require("../common/script"); const brand_1 = require("../common/brand"); const user_prompt_1 = require("../services/user-prompt"); const logger_1 = require("../services/logger"); const environment_1 = require("../services/environment"); const runTasks = async (compileAndLoad, nuke) => script_1.Script.init(`boost ${brand_1.default.dangerize('nuke')} [${(0, environment_1.currentEnvironment)()}] 🧨`, compileAndLoad) .step('Removing', (config) => nuke(config)) .info('Removal complete!') .done(); async function askToConfirmRemoval(prompter, force, config) { if (force) return config; const configuration = await config; const appName = await prompter.defaultOrPrompt(null, 'Please, enter the app name to confirm deletion of all resources:'); if (appName == configuration.appName) { return configuration; } else { throw new Error('Wrong app name, stopping nuke!'); } } class Nuke extends base_command_1.default { async run() { const { flags } = await this.parse(Nuke); if ((0, environment_1.initializeEnvironment)(logger_1.logger, flags.environment)) { await runTasks(askToConfirmRemoval(new user_prompt_1.default(), flags.force, (0, config_service_1.compileProjectAndLoadConfig)(process.cwd())), provider_service_1.nukeCloudProviderResources); } } async catch(fullError) { const { flags: { verbose }, } = await this.parse(Nuke); if (verbose) { console.error(fullError.message); } return super.catch(fullError); } } Nuke.description = 'Remove all resources used by the current application as configured in your `index.ts` file.'; Nuke.flags = { help: core_1.Flags.help({ char: 'h' }), environment: core_1.Flags.string({ char: 'e', description: 'environment configuration to run', }), force: core_1.Flags.boolean({ char: 'f', description: 'Run nuke without asking for confirmation. Be EXTRA CAUTIOUS with this option, all your application data will be irreversibly DELETED without confirmation.', }), verbose: core_1.Flags.boolean({ description: 'display full error messages', default: false, }), }; exports.default = Nuke;