51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import * as plugins from '../../plugins.js';
|
|
import { registerIpcCommand } from '../registration/index.js';
|
|
import { tspmIpcClient } from '../../client/tspm.ipcclient.js';
|
|
|
|
export function registerResetCommand(smartcli: plugins.smartcli.Smartcli) {
|
|
registerIpcCommand(
|
|
smartcli,
|
|
'reset',
|
|
async () => {
|
|
console.log('This will stop all processes and clear saved configurations.');
|
|
const confirmed = await plugins.smartinteract.SmartInteract.getCliConfirmation(
|
|
'Are you sure you want to reset TSPM? (stops all and removes configs)',
|
|
false,
|
|
);
|
|
|
|
if (!confirmed) {
|
|
console.log('Reset cancelled. No changes made.');
|
|
return;
|
|
}
|
|
|
|
// Stop all processes first
|
|
const stopAllRes = await tspmIpcClient.request('stopAll', {});
|
|
if (stopAllRes.failed.length) {
|
|
console.log(
|
|
`Stopped ${stopAllRes.stopped.length}, ${stopAllRes.failed.length} failed to stop. Proceeding with config reset...`,
|
|
);
|
|
} else {
|
|
console.log(`Stopped ${stopAllRes.stopped.length} processes.`);
|
|
}
|
|
|
|
// List all processes/configs currently known
|
|
const listRes = await tspmIpcClient.request('list', {});
|
|
|
|
// Remove each config
|
|
for (const proc of listRes.processes) {
|
|
try {
|
|
// Prefer 'remove' which handles stop-if-running semantics as well
|
|
await tspmIpcClient.request('remove', { id: proc.id });
|
|
console.log(`Removed config for process ${proc.id}.`);
|
|
} catch (err) {
|
|
console.error(`Failed to remove config for ${proc.id}:`, (err as Error)?.message || String(err));
|
|
}
|
|
}
|
|
|
|
console.log('TSPM has been reset: processes stopped and configs cleared.');
|
|
},
|
|
{ actionLabel: 'reset TSPM' },
|
|
);
|
|
}
|
|
|