UNPKG

langcode

Version:

A Plugin-Based Framework for Managing and Using LangChain

92 lines (91 loc) 3.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DockerFastCommands = void 0; const child_process_1 = require("child_process"); const util_1 = require("util"); const core_1 = require("../../core"); const execAsync = (0, util_1.promisify)(child_process_1.exec); /** * Utility class for executing frequently used Docker commands. */ class DockerFastCommands { constructor(loggerArgs) { this.logger = (0, core_1.logger)(loggerArgs); } /** * Lists all Docker containers. (`docker ps -a`) * @returns A list of all containers (running and stopped). */ async dockerPs() { var _a, _b; (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("ℹ️ Running command: docker ps -a"); const result = await this.exec("docker ps -a"); (_b = this.logger) === null || _b === void 0 ? void 0 : _b.success("✅ Command executed: docker ps -a"); return result; } /** * Lists all Docker images. (`docker images`) * @returns A list of all Docker images on the system. */ async dockerImages() { var _a, _b; (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("ℹ️ Running command: docker images"); const result = await this.exec("docker images"); (_b = this.logger) === null || _b === void 0 ? void 0 : _b.success("✅ Command executed: docker images"); return result; } /** * Shows resource usage statistics for containers. (`docker stats --no-stream`) * @returns Real-time statistics of container CPU, memory, and I/O usage. */ async dockerStats() { var _a, _b; (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("ℹ️ Running command: docker stats --no-stream"); const result = await this.exec("docker stats --no-stream"); (_b = this.logger) === null || _b === void 0 ? void 0 : _b.success("✅ Command executed: docker stats --no-stream"); return result; } /** * Displays detailed Docker system information. (`docker info`) * @returns System-wide Docker configuration and usage info. */ async dockerInfo() { var _a, _b; (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("ℹ️ Running command: docker info"); const result = await this.exec("docker info"); (_b = this.logger) === null || _b === void 0 ? void 0 : _b.success("✅ Command executed: docker info"); return result; } /** * Lists all Docker networks. (`docker network ls`) * @returns A list of all Docker-defined networks. */ async dockerNetworks() { var _a, _b; (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("ℹ️ Running command: docker network ls"); const result = await this.exec("docker network ls"); (_b = this.logger) === null || _b === void 0 ? void 0 : _b.success("✅ Command executed: docker network ls"); return result; } /** * Lists all Docker volumes. (`docker volume ls`) * @returns A list of all Docker volumes. */ async dockerVolumes() { var _a, _b; (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("ℹ️ Running command: docker volume ls"); const result = await this.exec("docker volume ls"); (_b = this.logger) === null || _b === void 0 ? void 0 : _b.success("✅ Command executed: docker volume ls"); return result; } /** * Internal helper to execute a shell command. * @param cmd The command to be executed. * @returns The trimmed stdout output from the command. */ async exec(cmd) { const { stdout } = await execAsync(cmd); return stdout.trim(); } } exports.DockerFastCommands = DockerFastCommands;