35 lines
1.5 KiB
TypeScript
35 lines
1.5 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 registerDeleteCommand(smartcli: plugins.smartcli.Smartcli) {
|
|
registerIpcCommand(
|
|
smartcli,
|
|
['delete', 'remove'],
|
|
async (argvArg: CliArguments) => {
|
|
const target = argvArg._[1];
|
|
if (!target) {
|
|
console.error('Error: Please provide a process target');
|
|
console.log('Usage: tspm delete <id|id:N|name:LABEL> | tspm remove <id|id:N|name:LABEL>');
|
|
return;
|
|
}
|
|
|
|
// Determine if command was 'remove' to use the new IPC route, otherwise 'delete'
|
|
const cmd = String(argvArg._[0]);
|
|
const isRemoveAlias = cmd === 'remove';
|
|
console.log(`${isRemoveAlias ? 'Removing' : 'Deleting'} process: ${target}`);
|
|
const resolved = await tspmIpcClient.request('resolveTarget', { target: String(target) });
|
|
// Always call daemon 'delete'; 'remove' is CLI alias only
|
|
const response = await tspmIpcClient.request('delete', { id: resolved.id } as any);
|
|
|
|
if (response.success) {
|
|
console.log(`✓ ${response.message || (isRemoveAlias ? 'Removed successfully' : 'Deleted successfully')}`);
|
|
} else {
|
|
console.error(`✗ Failed to ${isRemoveAlias ? 'remove' : 'delete'} process: ${response.message}`);
|
|
}
|
|
},
|
|
{ actionLabel: 'delete/remove process' },
|
|
);
|
|
}
|