Files
tspm/ts/cli/commands/process/restart.ts

48 lines
1.8 KiB
TypeScript

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 target or "all"');
console.log('Usage:');
console.log(' tspm restart <id | id:N | name:LABEL>');
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 target = String(arg);
console.log(`Restarting process: ${target}`);
const resolved = await tspmIpcClient.request('resolveTarget', { target });
const response = await tspmIpcClient.request('restart', { id: resolved.id });
console.log(`✓ Process restarted successfully`);
console.log(` ID: ${response.processId}${resolved.name ? ` (name: ${resolved.name})` : ''}`);
console.log(` PID: ${response.pid || 'N/A'}`);
console.log(` Status: ${response.status}`);
},
{ actionLabel: 'restart process' },
);
}