@augment-vir/node
Version:
A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.
19 lines (18 loc) • 741 B
JavaScript
import { runShellCommand } from '../../augments/terminal/shell.js';
export async function getContainerInfo(containerNameOrId) {
const command = `docker inspect '${containerNameOrId}'`;
const output = await runShellCommand(command);
if (output.stderr.includes('Error: No such object')) {
return undefined;
}
const parsedOutput = JSON.parse(output.stdout);
/** Edge cases that I don't know how to intentionally trigger. */
/* node:coverage ignore next 5 */
if (parsedOutput.length === 0) {
throw new Error(`Got no output from "${command}"`);
}
else if (parsedOutput.length > 1) {
throw new Error(`Got more than one output from "${command}"`);
}
return parsedOutput[0];
}