Skip to content

Commit

Permalink
Merge pull request #6 from KernelDeimos/master
Browse files Browse the repository at this point in the history
refactor: early return in fallback behavior
  • Loading branch information
bitsnaps authored Feb 7, 2025
2 parents 745211e + 298d3ac commit 82c6bc9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ export async function execCommand(input) {
// Handle help command
const command = args[0];
showHelp(command);
} else if (cmd.startsWith('!')) {
return;
}
if (cmd.startsWith('!')) {
// Execute the command on the host machine
const hostCommand = input.slice(1); // Remove the "!"
exec(hostCommand, (error, stdout, stderr) => {
Expand All @@ -178,17 +180,20 @@ export async function execCommand(input) {
console.log(stdout);
console.log(chalk.green(`Press <Enter> to return.`));
});
} else if (commands[cmd]) {
return;
}
if (commands[cmd]) {
try {
await commands[cmd](args);
} catch (error) {
console.error(chalk.red(`Error executing command: ${error.message}`));
}
} else {
if (!['Y', 'N'].includes(cmd.toUpperCase()[0])) {
console.log(chalk.red(`Unknown command: ${cmd}`));
showHelp();
}
return;
}

if (!['Y', 'N'].includes(cmd.toUpperCase()[0])) {
console.log(chalk.red(`Unknown command: ${cmd}`));
showHelp();
}
}

Expand Down

0 comments on commit 82c6bc9

Please sign in to comment.