Files
szci/ts/mod_command/index.ts
2025-12-14 01:42:14 +00:00

31 lines
948 B
TypeScript

import { bash } from '../szci.bash.ts';
import { logger } from '../szci.logging.ts';
/**
* Executes a wrapped command passed via CLI arguments.
* Usage: szci command <your-command-here>
*
* This allows running arbitrary commands through szci's bash wrapper
* which handles nvm and other environment setup.
*/
export const command = async (): Promise<void> => {
// Skip 'deno', 'mod.ts', 'command' and get the rest
const commandArgs = Deno.args.slice(1); // Skip 'command'
if (commandArgs.length === 0) {
logger.log('error', 'No command specified. Usage: szci command <your-command>');
Deno.exit(1);
}
const wrappedCommand = commandArgs.join(' ');
logger.log('info', `Executing command: ${wrappedCommand}`);
try {
await bash(wrappedCommand);
logger.log('ok', 'Command executed successfully');
} catch (error) {
logger.log('error', `Command failed: ${(error as Error).message}`);
throw error;
}
};