I’m stuck on Stage #MG5(change to your stage, ex. #JM3).
I’ve tried manually adding all the paths for the commands but every time running the tests is checking for new commands which is not there in my path database. I’m not able to use the path module and fs module functionalities as it’s looking only for Windows file path for the command, my system is not POSIX Compliant(mention what you’ve tried so far).
Here are my logs:
include relevant logs here (please make sure to keep the backticks around this!)
And here’s a snippet of my code:
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt:"$ "
});
// Uncomment this block to pass the first stage
rl.prompt()
rl.on('line',(input)=>{
input=input.trim();
execCmd(input)
rl.prompt()
})
let CMDS=["echo","exit","type"]
let usr_bin=["ls"]
let _bin=["cat","cp","mkdir"]
let _usr_local_bin=["valid_command"]
let _tmp_foo=["my_exe"]
function execCmd(command){
const{cmd,args}=getCmd(command)
if(cmd==="echo")
{
console.log(args.join(" "))
}
else if(cmd==="exit")
{
process.exit(0)
}
else if(cmd==="type")
{
printType(args[0])
}
else{
console.log(`${cmd}: command not found`)
}
}
function getCmd(command)
{
args=command.split(/\s+/)
cmd=args[0]
args.shift()
return {cmd,args}
}
function printType(cmdName)
{
let found=false;
if(CMDS.includes(cmdName))
{
console.log(`${cmdName} is a shell builtin`)
found=true
}
else if(usr_bin.includes(cmdName))
{
console.log(`${cmdName} is /usr/bin/${cmdName}`)
found=true
}
else if(_usr_local_bin.includes(cmdName))
{
console.log(`${cmdName} is /usr/bin/${cmdName}`)
found=true
}
else if(_bin.includes(cmdName))
{
console.log(`${cmdName} is /bin/${cmdName}`)
found=true
}
else if(_tmp_foo.includes(cmdName))
{
console.log(`${cmdName} is tmp/foo/${cmdName}`)
found=true
}
if(!found)
{
console.log(`${cmdName}: not found`)
}
}
include relevant code here (please make sure to keep the backticks around this!)