Skip to content

Commit 82c6bc9

Browse files
authored
Merge pull request #6 from KernelDeimos/master
refactor: early return in fallback behavior
2 parents 745211e + 298d3ac commit 82c6bc9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/executor.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ export async function execCommand(input) {
163163
// Handle help command
164164
const command = args[0];
165165
showHelp(command);
166-
} else if (cmd.startsWith('!')) {
166+
return;
167+
}
168+
if (cmd.startsWith('!')) {
167169
// Execute the command on the host machine
168170
const hostCommand = input.slice(1); // Remove the "!"
169171
exec(hostCommand, (error, stdout, stderr) => {
@@ -178,17 +180,20 @@ export async function execCommand(input) {
178180
console.log(stdout);
179181
console.log(chalk.green(`Press <Enter> to return.`));
180182
});
181-
} else if (commands[cmd]) {
183+
return;
184+
}
185+
if (commands[cmd]) {
182186
try {
183187
await commands[cmd](args);
184188
} catch (error) {
185189
console.error(chalk.red(`Error executing command: ${error.message}`));
186190
}
187-
} else {
188-
if (!['Y', 'N'].includes(cmd.toUpperCase()[0])) {
189-
console.log(chalk.red(`Unknown command: ${cmd}`));
190-
showHelp();
191-
}
191+
return;
192+
}
193+
194+
if (!['Y', 'N'].includes(cmd.toUpperCase()[0])) {
195+
console.log(chalk.red(`Unknown command: ${cmd}`));
196+
showHelp();
192197
}
193198
}
194199

0 commit comments

Comments
 (0)