forked from redhat-developer/vscode-openshift-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress.ts
More file actions
47 lines (42 loc) · 2.14 KB
/
progress.ts
File metadata and controls
47 lines (42 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
'use strict';
import * as vscode from 'vscode';
import * as odoctl from '../odo';
import { CliExitData } from '../cli';
import { ExecException } from 'child_process';
export interface Step {
command: string;
increment: number;
total?: number;
}
export class Progress {
static execWithProgress(options, steps: Step[], odo: odoctl.Odo): Thenable<void> {
return vscode.window.withProgress(options,
(progress: vscode.Progress<{increment: number, message: string}>, token: vscode.CancellationToken) => {
const calls: (()=>Promise<any>)[] = [];
steps.reduce((previous: Step, current: Step, currentIndex: number, steps: Step[])=> {
current.total = previous.total + current.increment;
calls.push (() => {
return Promise.resolve()
.then(() => progress.report({increment: previous.increment, message: `${previous.total}%` }))
.then(() => odo.execute(current.command))
.then(() => {
if (currentIndex+1 === steps.length) {
progress.report({
increment: current.increment,
message: `${current.total}%`
});
}
});
});
return current;
}, {increment: 0, command: "", total: 0});
return calls.reduce<Promise<any>>((previous: Promise<any>, current: ()=>Promise<any>, index: number, calls: (()=>Promise<any>)[])=> {
return previous.then(current);
}, Promise.resolve());
});
}
}