feat(cli): Add interactive edit flow to CLI and improve UX
This commit is contained in:
@@ -20,6 +20,7 @@ export function registerAddCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
console.log(' --watch Watch for file changes');
|
||||
console.log(' --watch-paths <paths> Comma-separated paths');
|
||||
console.log(' --autorestart Auto-restart on crash (default true)');
|
||||
console.log(' -i, --interactive Enter interactive edit mode after adding');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -29,6 +30,9 @@ export function registerAddCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
? parseMemoryString(argvArg.memory)
|
||||
: 512 * 1024 * 1024;
|
||||
|
||||
// Check for interactive flag
|
||||
const isInteractive = argvArg.i || argvArg.interactive;
|
||||
|
||||
// Resolve .ts single-file execution via tsx if needed
|
||||
const parts = script.split(' ');
|
||||
const first = parts[0];
|
||||
@@ -112,6 +116,12 @@ export function registerAddCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
|
||||
console.log('✓ Added');
|
||||
console.log(` Assigned ID: ${response.id}`);
|
||||
|
||||
// If interactive flag is set, enter edit mode
|
||||
if (isInteractive) {
|
||||
const { interactiveEditProcess } = await import('../../helpers/interactive-edit.js');
|
||||
await interactiveEditProcess(response.id);
|
||||
}
|
||||
},
|
||||
{ actionLabel: 'add process config' },
|
||||
);
|
||||
|
@@ -16,58 +16,12 @@ export function registerEditCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Resolve and load current config
|
||||
// Resolve the target to get the process ID
|
||||
const resolved = await tspmIpcClient.request('resolveTarget', { target: String(target) });
|
||||
const { config } = await tspmIpcClient.request('describe', { id: resolved.id });
|
||||
|
||||
// Interactive editing is temporarily disabled - needs smartinteract API update
|
||||
console.log('Interactive editing is temporarily disabled.');
|
||||
console.log('Current configuration:');
|
||||
console.log(` Name: ${config.name}`);
|
||||
console.log(` Command: ${config.command}`);
|
||||
console.log(` Directory: ${config.projectDir}`);
|
||||
console.log(` Memory: ${formatMemory(config.memoryLimitBytes)}`);
|
||||
console.log(` Auto-restart: ${config.autorestart}`);
|
||||
console.log(` Watch: ${config.watch ? 'enabled' : 'disabled'}`);
|
||||
|
||||
// For now, just update environment variables to current
|
||||
const essentialEnvVars: NodeJS.ProcessEnv = {
|
||||
PATH: process.env.PATH || '',
|
||||
HOME: process.env.HOME,
|
||||
USER: process.env.USER,
|
||||
SHELL: process.env.SHELL,
|
||||
LANG: process.env.LANG,
|
||||
LC_ALL: process.env.LC_ALL,
|
||||
// Node.js specific
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
NODE_PATH: process.env.NODE_PATH,
|
||||
// npm/pnpm/yarn paths
|
||||
npm_config_prefix: process.env.npm_config_prefix,
|
||||
// Include any TSPM_ prefixed vars
|
||||
...Object.fromEntries(
|
||||
Object.entries(process.env).filter(([key]) => key.startsWith('TSPM_'))
|
||||
),
|
||||
};
|
||||
|
||||
// Remove undefined values
|
||||
Object.keys(essentialEnvVars).forEach(key => {
|
||||
if (essentialEnvVars[key] === undefined) {
|
||||
delete essentialEnvVars[key];
|
||||
}
|
||||
});
|
||||
|
||||
// Update environment variables
|
||||
const updates = {
|
||||
env: { ...(config.env || {}), ...essentialEnvVars }
|
||||
};
|
||||
|
||||
const updateResponse = await tspmIpcClient.request('update', {
|
||||
id: resolved.id,
|
||||
updates,
|
||||
});
|
||||
|
||||
console.log('✓ Environment variables updated');
|
||||
console.log(' Process configuration updated successfully');
|
||||
// Use the shared interactive edit function
|
||||
const { interactiveEditProcess } = await import('../../helpers/interactive-edit.js');
|
||||
await interactiveEditProcess(resolved.id);
|
||||
},
|
||||
{ actionLabel: 'edit process config' },
|
||||
);
|
||||
|
@@ -14,7 +14,9 @@ export function registerListCommand(smartcli: plugins.smartcli.Smartcli) {
|
||||
const processes = response.processes;
|
||||
|
||||
if (processes.length === 0) {
|
||||
console.log('No processes running.');
|
||||
console.log('No processes configured.');
|
||||
console.log('Use "tspm add <command>" to add one, e.g.:');
|
||||
console.log(' tspm add "pnpm start"');
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user