import * as plugins from '../../../plugins.js'; import { tspmIpcClient } from '../../../client/tspm.ipcclient.js'; import type { CliArguments } from '../../types.js'; import { registerIpcCommand } from '../../registration/index.js'; export function registerRestartCommand(smartcli: plugins.smartcli.Smartcli) { registerIpcCommand( smartcli, 'restart', async (argvArg: CliArguments) => { const arg = argvArg._[1]; if (!arg) { console.error('Error: Please provide a process ID or "all"'); console.log('Usage:'); console.log(' tspm restart '); console.log(' tspm restart all'); return; } if (String(arg).toLowerCase() === 'all') { console.log('Restarting all processes...'); const res = await tspmIpcClient.request('restartAll', {}); if (res.restarted.length > 0) { console.log(`✓ Restarted ${res.restarted.length} processes:`); for (const id of res.restarted) console.log(` - ${id}`); } if (res.failed.length > 0) { console.log(`✗ Failed to restart ${res.failed.length} processes:`); for (const f of res.failed) console.log(` - ${f.id}: ${f.error}`); process.exitCode = 1; } return; } const id = String(arg); console.log(`Restarting process: ${id}`); const response = await tspmIpcClient.request('restart', { id }); console.log(`✓ Process restarted successfully`); console.log(` ID: ${response.processId}`); console.log(` PID: ${response.pid || 'N/A'}`); console.log(` Status: ${response.status}`); }, { actionLabel: 'restart process' }, ); }