UNPKG

fivem-docker-cli

Version:

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

64 lines (54 loc) 1.76 kB
const { Command } = require('@oclif/command'); const Docker = require('dockerode'); const exec = require('child_process').exec; const { getPorts } = require('../app'); // Initialization const docker = new Docker({socketPath: '/var/run/docker.sock'}); class StatusCommand extends Command { async run() { const table = []; // Get list of containers const containers = docker.listContainers({ all: true, }).then(list => { let ports; // Iterate through the containers list.forEach(container => { // Get ports for container ports = getPorts(container) .then((ports) => { for (let i in ports) { if (ports) { ports = ports + '\n' + ports[i].External + '+' + ports[i].Internal + '/' + ports[i].type; } else { ports = ports[i].External + '+' + ports[i].Internal + '/' + ports[i].type; } } }).then((ports) => { console.log('Ports: ' + ports); return ports; }).catch((err) => console.error(err)); // Add container to table if (true) { table.push({ Name: container.Names.toString().slice(1), ID: container.Id.slice(0, 11), Ports: ports, Status: container.Status, State: container.State, }); } // Display Table if (table.length === containers.length) { console.log('Container Status:'); console.table(table); } }); }).catch(err => { console.error(err); }); } } StatusCommand.description = `Display status of all FiveM Docker Containers. `; module.exports = StatusCommand;