Files
phorge.fr/commands.js
l-nmch f45a108808
All checks were successful
Docker Build and Push for Main Branch / docker (push) Successful in 11m31s
chore(core): Added bare TCP access
2026-05-11 15:50:11 +02:00

69 lines
1.7 KiB
JavaScript

const services = [
{ name: 'Dev Workspaces', url: 'https://coder.phorge.fr' },
{ name: 'Monitoring', url: 'https://monitoring.phorge.fr' },
{ name: 'Status page', url: 'https://status.phorge.fr/status' },
{ name: 'Git', url: 'https://git.phorge.fr' },
{ name: 'IaaS', url: 'https://iaas.phorge.fr' },
];
const commands = [
{
names: ['/services'],
description: 'Displays available services',
execute: (socket) => {
socket.write('Available services:\r\n');
for (const service of services) {
socket.write(`- ${service.name}: ${service.url}\r\n`);
}
},
},
{
names: ['/help', 'help'],
description: 'Displays command help',
execute: (socket) => {
socket.write('Available commands:\r\n');
for (const command of commands) {
socket.write(`- ${command.names[0]}: ${command.description}\r\n`);
}
},
},
{
names: ['/exit', 'quit'],
description: 'Exits the terminal session',
execute: (socket) => {
socket.write('Goodbye.\r\n');
socket.end();
},
},
];
const resolveCommand = (input) => {
const normalized = input.trim().toLowerCase();
return commands.find((command) => command.names.includes(normalized));
};
const handleCommand = (socket, input) => {
const trimmed = input.trim();
if (!trimmed) {
socket.write('phorge> ');
return;
}
const command = resolveCommand(trimmed);
if (command) {
command.execute(socket);
if (command.names.includes('/exit') || command.names.includes('quit')) {
return;
}
} else {
socket.write(`Unknown command : ${trimmed}\r\n`);
socket.write('Type /help for assistance.\r\n');
}
socket.write('phorge> ');
};
module.exports = {
handleCommand,
};