UNPKG

fivem-docker-cli

Version:

Command-line tool to create and administer FiveM Servers running in Docker.

65 lines (57 loc) 2.02 kB
const { Command } = require("@oclif/command"); const Docker = require("dockerode"); const { getPorts } = require("../modules/getPorts"); // Initialization const docker = new Docker({ socketPath: "/var/run/docker.sock" }); class StatusCommand extends Command { async run() { // Get list of containers docker .listContainers({ all: true }) .then(containers => { const table = []; // Iterate through the containers containers.forEach(container => { let ports; // Get ports for container getPorts(container) .then(p => { for (let i in p) { if (ports) { ports = ports + ", " + p[i].External + ":" + p[i].Internal + "/" + p[i].Type; } else { ports = p[i].External + ":" + p[i].Internal + "/" + p[i].Type; } } }) .then(() => { //Build Table table.push({ Name: container.Names.toString().slice(1), ID: container.Id.slice(0, 11), Ports: ports, Status: container.Status, State: container.State }); }) .then(() => { // Display Table if (table.length === containers.length) { console.log('Container Status:'); console.table(table); } else if (!table.length) { console.error('There are no FiveM server Docker containers available. Create a new container using "fivem init".'); } else { console.error('There was an error displaying the container status.'); } }) .catch(err => console.error(err)); }); }) .catch((err) => console.error(err)); } } StatusCommand.description = `Display status of all FiveM server Docker containers.`; module.exports = StatusCommand;