feat(cli): Add reset CLI command to stop all processes and clear saved configurations; integrate interactive confirmation and client plugin updates
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tspm',
|
||||
version: '4.1.1',
|
||||
version: '4.2.0',
|
||||
description: 'a no fuzz process manager'
|
||||
}
|
||||
|
50
ts/cli/commands/reset.ts
Normal file
50
ts/cli/commands/reset.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
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' },
|
||||
);
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ import { registerRestartAllCommand } from './commands/batch/restart-all.js';
|
||||
import { registerDaemonCommand } from './commands/daemon/index.js';
|
||||
import { registerEnableCommand } from './commands/service/enable.js';
|
||||
import { registerDisableCommand } from './commands/service/disable.js';
|
||||
import { registerResetCommand } from './commands/reset.js';
|
||||
|
||||
// Export types for external use
|
||||
export type { CliArguments } from './types.js';
|
||||
@@ -65,6 +66,9 @@ export const run = async (): Promise<void> => {
|
||||
registerEnableCommand(smartcliInstance);
|
||||
registerDisableCommand(smartcliInstance);
|
||||
|
||||
// Maintenance commands
|
||||
registerResetCommand(smartcliInstance);
|
||||
|
||||
// Start parsing commands
|
||||
smartcliInstance.startParse();
|
||||
};
|
||||
|
6
ts/client/plugins.ts
Normal file
6
ts/client/plugins.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
// Minimal plugin set for lightweight client startup
|
||||
import * as path from 'node:path';
|
||||
import * as smartipc from '@push.rocks/smartipc';
|
||||
|
||||
export { path, smartipc };
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import * as plugins from '../plugins.js';
|
||||
import * as plugins from './plugins.js';
|
||||
import * as paths from '../paths.js';
|
||||
|
||||
import type {
|
||||
|
@@ -12,9 +12,10 @@ import * as smartcli from '@push.rocks/smartcli';
|
||||
import * as smartdaemon from '@push.rocks/smartdaemon';
|
||||
import * as smartipc from '@push.rocks/smartipc';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartinteract from '@push.rocks/smartinteract';
|
||||
|
||||
// Export with explicit module types
|
||||
export { npmextra, projectinfo, smartcli, smartdaemon, smartipc, smartpath };
|
||||
export { npmextra, projectinfo, smartcli, smartdaemon, smartipc, smartpath, smartinteract };
|
||||
|
||||
// third-party scope
|
||||
import psTree from 'ps-tree';
|
||||
|
Reference in New Issue
Block a user