Skip to content

Commit

Permalink
Tekton: Delete commands should show confirmation info message and r…
Browse files Browse the repository at this point in the history
…un without terminal
  • Loading branch information
sudhirverma committed Dec 5, 2019
1 parent dc0317a commit ea3a1a9
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 20 deletions.
12 changes: 10 additions & 2 deletions src/tekton/clustertask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import { TektonItem } from './tektonitem';
import { TektonNode, Command } from '../tkn';
import { Progress } from '../util/progress';
import { window } from 'vscode';

export class ClusterTask extends TektonItem {

Expand All @@ -16,8 +18,14 @@ export class ClusterTask extends TektonItem {
if (clustertasks) { ClusterTask.tkn.executeInTerminal(Command.listClusterTasksinTerminal()); }
}

static async delete(clustertask: TektonNode): Promise<void> {
if (clustertask) { ClusterTask.tkn.executeInTerminal(Command.deleteClusterTask(clustertask.getName())); }
static async delete(clustertask: TektonNode): Promise<string> {
const value = await window.showWarningMessage(`Do you want to delete clustertask '${clustertask.getName()}\'?`, 'Yes', 'Cancel');
if (value === 'Yes') {
return Progress.execFunctionWithProgress(`Deleting the clustertask '${clustertask.getName()}'`, () =>
ClusterTask.tkn.execute(Command.deleteClusterTask(clustertask.getName())))
.then(() => `clustertask '${clustertask.getName()}' successfully deleted`)
.catch((err) => Promise.reject(`Failed to delete clustertask with error '${err}'`));
}
}

}
11 changes: 8 additions & 3 deletions src/tekton/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import * as cliInstance from '../cli';
import { Cli } from '../cli';
import * as k8s from 'vscode-kubernetes-tools-api';


export interface NameType {
name: string;
type: string;
Expand Down Expand Up @@ -271,8 +270,14 @@ export class Pipeline extends TektonItem {
if (pipeline) { Pipeline.tkn.executeInTerminal(Command.listPipelinesInTerminal(pipeline.getName())); }
}

static async delete(pipeline: TektonNode): Promise<void> {
if (pipeline) {Pipeline.tkn.executeInTerminal(Command.deletePipeline(pipeline.getName())); }
static async delete(pipeline: TektonNode): Promise<string> {
const value = await window.showWarningMessage(`Do you want to delete pipeline '${pipeline.getName()}\'?`, 'Yes', 'Cancel');
if (value === 'Yes') {
return Progress.execFunctionWithProgress(`Deleting the pipeline '${pipeline.getName()}'`, () =>
Pipeline.tkn.execute(Command.deletePipeline(pipeline.getName())))
.then(() => `pipeline '${pipeline.getName()}' successfully deleted`)
.catch((err) => Promise.reject(`Failed to delete pipeline with error '${err}'`));
}
}

}
12 changes: 10 additions & 2 deletions src/tekton/pipelineresource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import { TektonItem } from './tektonitem';
import { TektonNode, Command } from '../tkn';
import * as k8s from 'vscode-kubernetes-tools-api';
import { Progress } from '../util/progress';
import { window } from 'vscode';

export class PipelineResource extends TektonItem {

Expand All @@ -18,8 +20,14 @@ export class PipelineResource extends TektonItem {
if (pipelineresource) { PipelineResource.tkn.executeInTerminal(Command.listPipelineResourcesInTerminal(pipelineresource.getName())); }
}

static async delete(pipelineresource: TektonNode): Promise<void> {
if (pipelineresource) { PipelineResource.tkn.executeInTerminal(Command.deletePipelineResource(pipelineresource.getName())); }
static async delete(pipelineresource: TektonNode): Promise<string> {
const value = await window.showWarningMessage(`Do you want to delete resource '${pipelineresource.getName()}\'?`, 'Yes', 'Cancel');
if (value === 'Yes') {
return Progress.execFunctionWithProgress(`Deleting the resource '${pipelineresource.getName()}'`, () =>
PipelineResource.tkn.execute(Command.deletePipelineResource(pipelineresource.getName())))
.then(() => `resource '${pipelineresource.getName()}' successfully deleted`)
.catch((err) => Promise.reject(`Failed to delete resource with error '${err}'`));
}
}

}
13 changes: 10 additions & 3 deletions src/tekton/pipelinerun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import { TektonItem } from './tektonitem';
import { TektonNode, Command } from '../tkn';
import * as k8s from 'vscode-kubernetes-tools-api';
import { window } from 'vscode';
import { Progress } from '../util/progress';

export class PipelineRun extends TektonItem {

Expand Down Expand Up @@ -44,8 +45,14 @@ export class PipelineRun extends TektonItem {
if (pipelinerun) { PipelineRun.tkn.executeInTerminal(Command.cancelPipelineRun(pipelinerun.getName())); }
}

static async delete(pipelinerun: TektonNode): Promise<void> {
if (pipelinerun) { PipelineRun.tkn.executeInTerminal(Command.deletePipelineRun(pipelinerun.getName())); }
static async delete(pipelinerun: TektonNode): Promise<string> {
const value = await window.showWarningMessage(`Do you want to delete pipelinerun '${pipelinerun.getName()}\'?`, 'Yes', 'Cancel');
if (value === 'Yes') {
return Progress.execFunctionWithProgress(`Deleting the pipelinerun '${pipelinerun.getName()}'`, () =>
PipelineRun.tkn.execute(Command.deletePipelineRun(pipelinerun.getName())))
.then(() => `pipelinerun '${pipelinerun.getName()}' successfully deleted`)
.catch((err) => Promise.reject(`Failed to delete pipelinerun with error '${err}'`));
}
}

}
12 changes: 10 additions & 2 deletions src/tekton/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import { TektonItem } from './tektonitem';
import { TektonNode, Command } from '../tkn';
import { window } from 'vscode';
import { Progress } from '../util/progress';

export class Task extends TektonItem {

Expand All @@ -18,7 +20,13 @@ export class Task extends TektonItem {
if (task) { Task.tkn.executeInTerminal(Command.listTasksinTerminal()); }
}

static async delete(task: TektonNode): Promise<void> {
if (task) { Task.tkn.executeInTerminal(Command.deleteTask(task.getName())); }
static async delete(task: TektonNode): Promise<string> {
const value = await window.showWarningMessage(`Do you want to delete task '${task.getName()}\'?`, 'Yes', 'Cancel');
if (value === 'Yes') {
return Progress.execFunctionWithProgress(`Deleting the task '${task.getName()}'`, () =>
Task.tkn.execute(Command.deleteTask(task.getName())))
.then(() => `task '${task.getName()}' successfully deleted`)
.catch((err) => Promise.reject(`Failed to delete task with error '${err}'`));
}
}
}
12 changes: 10 additions & 2 deletions src/tekton/taskrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import { TektonItem } from './tektonitem';
import { TektonNode, Command } from '../tkn';
import { window } from 'vscode';
import { Progress } from '../util/progress';

export class TaskRun extends TektonItem {

Expand All @@ -20,7 +22,13 @@ export class TaskRun extends TektonItem {
if (taskrun) { TaskRun.tkn.executeInTerminal(Command.showTaskRunLogs(taskrun.getName())); }
}

static async delete(taskrun: TektonNode): Promise<void> {
if (taskrun) { TaskRun.tkn.executeInTerminal(Command.deleteTaskRun(taskrun.getName())); }
static async delete(taskrun: TektonNode): Promise<string> {
const value = await window.showWarningMessage(`Do you want to delete taskrun '${taskrun.getName()}\'?`, 'Yes', 'Cancel');
if (value === 'Yes') {
return Progress.execFunctionWithProgress(`Deleting the taskrun '${taskrun.getName()}'`, () =>
TaskRun.tkn.execute(Command.deleteTaskRun(taskrun.getName())))
.then(() => `taskrun '${taskrun.getName()}' successfully deleted`)
.catch((err) => Promise.reject(`Failed to delete taskrun with error '${err}'`));
}
}
}
12 changes: 6 additions & 6 deletions src/tkn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class Command {
}
@verbose
static deletePipeline(name: string) {
return `tkn pipeline delete ${name}`;
return `tkn pipeline delete ${name} -f`;
}
@verbose
static listPipelineResources() {
Expand All @@ -126,7 +126,7 @@ export class Command {
}
@verbose
static deletePipelineResource(name: string) {
return `tkn resource delete ${name}`;
return `tkn resource delete ${name} -f`;
}
@verbose
static listPipelines() {
Expand Down Expand Up @@ -158,7 +158,7 @@ export class Command {
}
@verbose
static deletePipelineRun(name: string) {
return `tkn pipelinerun delete ${name}`;
return `tkn pipelinerun delete ${name} -f`;
}
@verbose
static showPipelineRunLogs(name: string) {
Expand All @@ -182,7 +182,7 @@ export class Command {
}
@verbose
static deleteTask(name: string) {
return `tkn task delete ${name}`;
return `tkn task delete ${name} -f`;
}
@verbose
static listClusterTasks(namespace?: string) {
Expand All @@ -193,15 +193,15 @@ export class Command {
}
@verbose
static deleteClusterTask(name: string) {
return `tkn task delete ${name}`;
return `tkn clustertask delete ${name} -f`;
}
@verbose
static showTaskRunLogs(name: string) {
return `tkn taskrun logs ${name}`;
}
@verbose
static deleteTaskRun(name: string) {
return `tkn taskrun delete ${name}`;
return `tkn taskrun delete ${name} -f`;
}
@verbose
static printTknVersion() {
Expand Down

0 comments on commit ea3a1a9

Please sign in to comment.