vscode-docker/commands/stop-container.ts

68 строки
2.4 KiB
TypeScript
Исходник Обычный вид История

import { dockerExplorerProvider } from '../dockerExtension';
import { ContainerNode } from '../explorer/models/containerNode';
import { reporter } from '../telemetry/telemetry';
2017-03-02 04:49:54 +03:00
import { docker } from './utils/docker-endpoint';
import { ContainerItem, quickPickContainer } from './utils/quick-pick-container';
import vscode = require('vscode');
2017-03-04 04:13:14 +03:00
const teleCmdId: string = 'vscode-docker.container.stop';
2016-09-14 08:20:20 +03:00
export async function stopContainer(context?: ContainerNode): Promise<void> {
let containersToStop: Docker.ContainerDesc[];
if (context && context.containerDesc) {
containersToStop = [context.containerDesc];
} else {
const opts = {
"filters": {
"status": ["restarting", "running", "paused"]
2016-09-20 19:47:56 +03:00
}
};
const selectedItem: ContainerItem = await quickPickContainer(true, opts);
if (selectedItem) {
if (selectedItem.label.toLowerCase().includes('all containers')) {
containersToStop = await docker.getContainerDescriptors(opts);
} else {
containersToStop = [selectedItem.containerDesc];
}
}
}
if (containersToStop) {
const numContainers: number = containersToStop.length;
let containerCounter: number = 0;
vscode.window.setStatusBarMessage("Docker: Stopping Container(s)...", new Promise((resolve, reject) => {
containersToStop.forEach((c) => {
// tslint:disable-next-line:no-function-expression // Grandfathered in
docker.getContainer(c.Id).stop(function (err: Error, data: any): void {
containerCounter++;
if (err) {
vscode.window.showErrorMessage(err.message);
dockerExplorerProvider.refreshContainers();
reject();
}
if (containerCounter === numContainers) {
dockerExplorerProvider.refreshContainers();
resolve();
}
});
});
}));
if (reporter) {
/* __GDPR__
"command" : {
"command" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
2016-09-14 08:20:20 +03:00
}
2017-06-06 03:55:05 +03:00
}
2018-07-07 02:49:46 +03:00
}