From 1c21d6c7297fcbdd949506921f8f9a43ad84dc2b Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Thu, 13 Feb 2020 15:52:42 +0200 Subject: [PATCH] Add confirmation to delete Che server (#506) Signed-off-by: Anatoliy Bazko --- README.md | 6 ++++-- src/commands/server/delete.ts | 22 +++++++++++++++++++++- yarn.lock | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2e0d6882d..32743da39 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ EXAMPLES $ chectl autocomplete --refresh-cache ``` -_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v0.1.4/src/commands/autocomplete/index.ts)_ +_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v0.1.5/src/commands/autocomplete/index.ts)_ ## `chectl devfile:generate` @@ -167,7 +167,7 @@ OPTIONS --all see all commands in CLI ``` -_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.1/src/commands/help.ts)_ +_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.3/src/commands/help.ts)_ ## `chectl server:debug` @@ -205,6 +205,8 @@ OPTIONS be deployed --listr-renderer=default|silent|verbose [default: default] Listr renderer + + --skip-deletion-check Skip user confirmation on deletion check ``` _See code: [src/commands/server/delete.ts](https://github.com/che-incubator/chectl/blob/v0.0.2/src/commands/server/delete.ts)_ diff --git a/src/commands/server/delete.ts b/src/commands/server/delete.ts index 65669dd6d..8839d3eef 100644 --- a/src/commands/server/delete.ts +++ b/src/commands/server/delete.ts @@ -8,7 +8,10 @@ * SPDX-License-Identifier: EPL-2.0 **********************************************************************/ +import { KubeConfig } from '@kubernetes/client-node' import { Command, flags } from '@oclif/command' +import { boolean } from '@oclif/command/lib/flags' +import { cli } from 'cli-ux' import * as Listrq from 'listr' import { cheNamespace, listrRenderer } from '../../common-flags' @@ -24,7 +27,11 @@ export default class Delete extends Command { static flags = { help: flags.help({ char: 'h' }), chenamespace: cheNamespace, - 'listr-renderer': listrRenderer + 'listr-renderer': listrRenderer, + 'skip-deletion-check': boolean({ + description: 'Skip user confirmation on deletion check', + default: false + }), } async run() { @@ -48,6 +55,19 @@ export default class Delete extends Command { tasks.add(helmTasks.deleteTasks(flags)) tasks.add(msAddonTasks.deleteTasks(flags)) + const kc = new KubeConfig() + kc.loadFromDefault() + + const cluster = kc.getCurrentCluster() + const context = kc.getContextObject(kc.getCurrentContext()) + + if (!flags['skip-deletion-check']) { + const confirmed = await cli.confirm(`You're going to remove Eclipse Che server in namespace '${context ? context.namespace : ''}' on server '${cluster ? cluster.server : ''}'. If you want to continue - press Y`) + if (!confirmed) { + this.exit(0) + } + } + await tasks.run() notifier.notify({ diff --git a/yarn.lock b/yarn.lock index 522fb6b98..71816df10 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1676,11 +1676,11 @@ ecc-jsbn@~0.1.1: "eclipse-che-operator@git://github.com/eclipse/che-operator#master": version "0.0.0" - resolved "git://github.com/eclipse/che-operator#29198304be0cb89d823b725fba72eafb78d9fd9a" + resolved "git://github.com/eclipse/che-operator#41f00fff311ce341623d1682ac349a0d0d1826e5" "eclipse-che@git://github.com/eclipse/che#master": version "0.0.0" - resolved "git://github.com/eclipse/che#95754848f677f735203b75d517e26cde12dd14cf" + resolved "git://github.com/eclipse/che#980379f3865dc339fd22c8aeaa8785c70012fd37" editorconfig@^0.15.0: version "0.15.3"