Currently, I'm in the process of developing a control panel using js and npm. I've run into an issue where I need to reset midway through the code without starting anew. Essentially, what I want is for the system to return to the menu after executing a command, rather than initiating a new instance.
This is the current state of my code:
( async function main() {
for (var d in dirs) {
dir("parent", `${dirs[d]}`);
}
//This section is placeholder code meant to run only once.
//Desired Re-entry Point
info(`Please Enter A Command!\nOr Enter 'Help'!`);
var rep = await query(`\nCommand: `);
rep = rep.toLowerCase();
switch(rep) {
case "help":
var help = require("./Commands/Help.js");
help.CmdList();
//Return to Re-Entry Point
break;
case "Start Server":
//Menu actions
//Go back to Re-Entry Point
break;
case "Stop Server":
break;
case "Create Server":
break;
case "Delete Server":
break;
default:
warn("Unknown Command!!");
break;
}
})();
The challenge I'm facing is that I don't want it to restart from the beginning, as there are certain parts at the start that should only be executed once. Apart from modularizing the code, is there a way to achieve this?